Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mongocxx/include/mongocxx/v1/delete_many_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class delete_many_options {
/// Return the current "comment" field.
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> const) comment() const;

class internal;
};

} // namespace v1
Expand Down
4 changes: 3 additions & 1 deletion src/mongocxx/include/mongocxx/v1/delete_one_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class delete_one_options {
///
/// Set the "writeConcern" field.
///
MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) write_concern(write_concern wc);
MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) write_concern(v1::write_concern wc);

///
/// Return the current "writeConcern" field.
Expand Down Expand Up @@ -146,6 +146,8 @@ class delete_one_options {
/// Return the current "comment" field.
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view> const) comment() const;

class internal;
};

} // namespace v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#pragma once

#include <mongocxx/v1/delete_many_options-fwd.hpp> // IWYU pragma: export
#include <mongocxx/v1/delete_one_options-fwd.hpp> // IWYU pragma: export

#include <mongocxx/config/prelude.hpp>

namespace mongocxx {
Expand All @@ -29,7 +32,7 @@ class delete_options;
namespace mongocxx {
namespace options {

using ::mongocxx::v_noabi::options::delete_options;
using v_noabi::options::delete_options;

} // namespace options
} // namespace mongocxx
Expand All @@ -40,3 +43,7 @@ using ::mongocxx::v_noabi::options::delete_options;
/// @file
/// Declares @ref mongocxx::v_noabi::options::delete_options.
///
/// @par Includes
/// - @ref mongocxx/v1/delete_many_options-fwd.hpp
/// - @ref mongocxx/v1/delete_one_options-fwd.hpp
///
177 changes: 158 additions & 19 deletions src/mongocxx/include/mongocxx/v_noabi/mongocxx/options/delete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@

#include <mongocxx/options/delete-fwd.hpp> // IWYU pragma: export

//

#include <bsoncxx/v1/document/value.hpp>
#include <bsoncxx/v1/types/value.hpp>

#include <mongocxx/v1/delete_many_options.hpp> // IWYU pragma: export
#include <mongocxx/v1/delete_one_options.hpp> // IWYU pragma: export

#include <utility>

#include <bsoncxx/document/view.hpp>
#include <bsoncxx/document/view_or_value.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/types/bson_value/view.hpp>
#include <bsoncxx/types/bson_value/view_or_value.hpp>

#include <mongocxx/hint.hpp>
Expand All @@ -34,6 +46,85 @@ namespace options {
///
class delete_options {
public:
///
/// Default initialization.
///
delete_options() = default;

///
/// Construct with the @ref mongocxx::v1 equivalent.
///
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() delete_options(v1::delete_many_options opts);

///
/// Construct with the @ref mongocxx::v1 equivalent.
///
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() delete_options(v1::delete_one_options opts);

///
/// Convert to the @ref mongocxx::v1 equivalent.
///
explicit operator v1::delete_many_options() const {
using bsoncxx::v_noabi::to_v1;
using mongocxx::v_noabi::to_v1;

v1::delete_many_options ret;

if (_collation) {
ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
}

if (_write_concern) {
ret.write_concern(to_v1(*_write_concern));
}

if (_hint) {
ret.hint(to_v1(*_hint));
}

if (_let) {
ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
}

if (_comment) {
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
}

return ret;
}

///
/// Convert to the @ref mongocxx::v1 equivalent.
///
explicit operator v1::delete_one_options() const {
using bsoncxx::v_noabi::to_v1;
using mongocxx::v_noabi::to_v1;

v1::delete_one_options ret;

if (_collation) {
ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
}

if (_write_concern) {
ret.write_concern(to_v1(*_write_concern));
}

if (_hint) {
ret.hint(to_v1(*_hint));
}

if (_let) {
ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
}

if (_comment) {
ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
}

return ret;
}

///
/// Sets the collation for this operation.
///
Expand All @@ -47,8 +138,10 @@ class delete_options {
/// @see
/// - https://www.mongodb.com/docs/manual/reference/collation/
///
MONGOCXX_ABI_EXPORT_CDECL(delete_options&)
collation(bsoncxx::v_noabi::document::view_or_value collation);
delete_options& collation(bsoncxx::v_noabi::document::view_or_value collation) {
_collation = std::move(collation);
return *this;
}

///
/// Retrieves the current collation for this operation.
Expand All @@ -59,8 +152,9 @@ class delete_options {
/// @see
/// - https://www.mongodb.com/docs/manual/reference/collation/
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
collation() const;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const& collation() const {
return _collation;
}

///
/// Sets the write_concern for this operation.
Expand All @@ -75,7 +169,10 @@ class delete_options {
/// @see
/// - https://www.mongodb.com/docs/manual/core/write-concern/
///
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) write_concern(write_concern wc);
delete_options& write_concern(write_concern wc) {
_write_concern = std::move(wc);
return *this;
}

///
/// The current write_concern for this operation.
Expand All @@ -86,8 +183,9 @@ class delete_options {
/// @see
/// - https://www.mongodb.com/docs/manual/core/write-concern/
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> const&)
write_concern() const;
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern() const {
return _write_concern;
}

///
/// Sets the index to use for this operation.
Expand All @@ -102,15 +200,19 @@ class delete_options {
/// A reference to the object on which this member function is being called. This facilitates
/// method chaining.
///
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) hint(mongocxx::v_noabi::hint index_hint);
delete_options& hint(v_noabi::hint index_hint) {
_hint = std::move(index_hint);
return *this;
}

///
/// Gets the current hint.
///
/// @return The current hint, if one is set.
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> const&)
hint() const;
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> const& hint() const {
return _hint;
}

///
/// Set the value of the let option.
Expand All @@ -122,16 +224,20 @@ class delete_options {
/// A reference to the object on which this member function is being called. This facilitates
/// method chaining.
///
MONGOCXX_ABI_EXPORT_CDECL(delete_options&) let(bsoncxx::v_noabi::document::view_or_value let);
delete_options& let(bsoncxx::v_noabi::document::view_or_value let) {
_let = std::move(let);
return *this;
}

///
/// Gets the current value of the let option.
///
/// @return
/// The current let option.
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const)
let() const;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const let() const {
return _let;
}

///
/// Set the value of the comment option.
Expand All @@ -143,22 +249,25 @@ class delete_options {
/// A reference to the object on which this member function is being called. This facilitates
/// method chaining.
///
MONGOCXX_ABI_EXPORT_CDECL(delete_options&)
comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment);
delete_options& comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
_comment = std::move(comment);
return *this;
}

///
/// Gets the current value of the comment option.
///
/// @return
/// The current comment option.
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const)
comment() const;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const comment() const {
return _comment;
}

private:
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> _write_concern;
bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::hint> _hint;
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> _write_concern;
bsoncxx::v_noabi::stdx::optional<v_noabi::hint> _hint;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _let;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> _comment;
};
Expand All @@ -167,9 +276,39 @@ class delete_options {
} // namespace v_noabi
} // namespace mongocxx

namespace mongocxx {
namespace v_noabi {

///
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
///
inline v_noabi::options::delete_options from_v1(v1::delete_many_options v) {
return {std::move(v)};
}

///
/// Convert to the @ref mongocxx::v_noabi equivalent of `v`.
///
inline v_noabi::options::delete_options from_v1(v1::delete_one_options v) {
return {std::move(v)};
}

// Ambiguous whether `v_noabi::options::delete_options` should be converted to `v1::delete_many_options` or
// `v1::delete_one_options`. Require users to explicitly cast to the expected type instead.
//
// v1::delete_many_options to_v1(v_noabi::options::delete_options const& v);
// v1::delete_one_options to_v1(v_noabi::options::delete_options const& v);

} // namespace v_noabi
} // namespace mongocxx

#include <mongocxx/config/postlude.hpp>

///
/// @file
/// Provides @ref mongocxx::v_noabi::options::delete_options.
///
/// @par Includes
/// - @ref mongocxx/v1/delete_many_options.hpp
/// - @ref mongocxx/v1/delete_one_options.hpp
///
Loading