Loading...
Searching...
No Matches
hint.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/hint-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/hint.hpp> // IWYU pragma: export
#include <string>
#include <utility>
#include <bsoncxx/document/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/document/view_or_value.hpp>
#include <bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/string/view_or_value.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/types/view.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class hint {
public:
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() hint(v1::hint hint);
explicit operator v1::hint() const {
if (_index_doc) {
return v1::hint{bsoncxx::v1::document::value{bsoncxx::v_noabi::to_v1(_index_doc->view())}};
}
return v1::hint{std::string{_index_string->view()}};
}
hint(bsoncxx::v_noabi::document::view_or_value index) : _index_doc{std::move(index)} {}
explicit hint(bsoncxx::v_noabi::string::view_or_value index) : _index_string(std::move(index)) {}
friend bool operator==(hint const& index_hint, std::string index) {
return index_hint._index_string == index;
}
friend bool operator==(hint const& index_hint, bsoncxx::v_noabi::document::view index) {
return index_hint._index_doc == index;
}
bsoncxx::v_noabi::types::view to_value() const {
if (_index_doc) {
return bsoncxx::v_noabi::types::view{bsoncxx::v_noabi::types::b_document{_index_doc->view()}};
}
return bsoncxx::v_noabi::types::view{bsoncxx::v_noabi::types::b_string{_index_string->view()}};
}
operator bsoncxx::v_noabi::types::view() const {
return this->to_value();
}
private:
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _index_doc;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::string::view_or_value> _index_string;
};
inline bool operator==(std::string str, hint const& hint) {
return hint == str;
}
inline bool operator!=(hint const& hint, std::string str) {
return !(hint == str);
}
inline bool operator!=(std::string str, hint const& hint) {
return !(hint == str);
}
inline bool operator==(bsoncxx::v_noabi::document::view doc, hint const& hint) {
return hint == doc;
}
inline bool operator!=(hint const& hint, bsoncxx::v_noabi::document::view doc) {
return !(hint == doc);
}
inline bool operator!=(bsoncxx::v_noabi::document::view doc, hint const& hint) {
return !(hint == doc);
}
inline v_noabi::hint from_v1(v1::hint v) {
return {std::move(v)};
}
inline v1::hint to_v1(v_noabi::hint const& v) {
return v1::hint{v};
}
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
using v_noabi::operator==;
using v_noabi::operator!=;
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::document::value
A BSON document.
Definition value.hpp:44
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
bsoncxx::v_noabi::string::view_or_value
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
mongocxx::hint::hint
hint(v1::hint hint)
Construct with the mongocxx::v1 equivalent.
mongocxx::v1::hint
Options related to a MongoDB query hint.
Definition hint.hpp:45
mongocxx::v_noabi::hint
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
mongocxx::v_noabi::hint::operator==
bool operator==(bsoncxx::v_noabi::document::view doc, hint const &hint)
Convenience methods to compare for equality against an index document.
Definition hint.hpp:163
mongocxx::v_noabi::hint::operator==
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
mongocxx::v_noabi::hint::operator!=
bool operator!=(hint const &hint, bsoncxx::v_noabi::document::view doc)
Convenience methods to compare for equality against an index document.
Definition hint.hpp:168
mongocxx::v_noabi::hint::operator!=
bool operator!=(bsoncxx::v_noabi::document::view doc, hint const &hint)
Convenience methods to compare for equality against an index document.
Definition hint.hpp:173
mongocxx::v_noabi::hint::to_value
bsoncxx::v_noabi::types::view to_value() const
Returns a bsoncxx::v_noabi::types::view representing this hint.
Definition hint.hpp:107
mongocxx::v_noabi::hint::operator!=
bool operator!=(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:148
mongocxx::v_noabi::hint::operator!=
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
mongocxx::v_noabi::hint::operator==
friend bool operator==(hint const &index_hint, bsoncxx::v_noabi::document::view index)
Convenience methods to compare for equality against an index document.
Definition hint.hpp:97
mongocxx::v_noabi::hint::hint
hint(bsoncxx::v_noabi::document::view_or_value index)
Constructs a new hint.
Definition hint.hpp:69
mongocxx::v_noabi::hint::operator==
friend bool operator==(hint const &index_hint, std::string index)
Convenience methods to compare for equality against an index name.
Definition hint.hpp:86
mongocxx::v_noabi::hint::hint
hint(v1::hint hint)
Construct with the mongocxx::v1 equivalent.
mongocxx::v_noabi::hint::hint
hint(bsoncxx::v_noabi::string::view_or_value index)
Constructs a new hint.
Definition hint.hpp:77
view_or_value.hpp
Provides bsoncxx::v_noabi::document::view_or_value.
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.
bsoncxx::v_noabi::document::view_or_value
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
bsoncxx::v_noabi::types::view
v_noabi::types::bson_value::view view
Equivalent to bsoncxx::v_noabi::types::bson_value::view.
Definition view-fwd.hpp:35
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
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.
view_or_value.hpp
Provides bsoncxx::v_noabi::string::view_or_value.
bsoncxx::v_noabi::types::b_document
A BSON document value.
Definition types.hpp:211
bsoncxx::v_noabi::types::b_string
A BSON UTF-8 encoded string value.
Definition types.hpp:177
types.hpp
Provides entities used to represent BSON types.
hint.hpp
Provides mongocxx::v1::hint.
value.hpp
Provides bsoncxx::v_noabi::document::value.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
view.hpp
Equivalent to bsoncxx/types/bson_value/view.hpp.
hint-fwd.hpp
Declares mongocxx::v_noabi::hint.