MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
hint.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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 <mongocxx/hint-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/hint.hpp> // IWYU pragma: export
22
23#include <string>
24#include <utility>
25
26#include <bsoncxx/document/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29#include <bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31#include <bsoncxx/types.hpp>
33
35
36namespace mongocxx {
37namespace v_noabi {
38
42class hint {
43 public:
47 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() hint(v1::hint hint);
48
52 explicit operator v1::hint() const {
53 if (_index_doc) {
55 }
56
57 return v1::hint{std::string{_index_string->view()}};
58 }
59
69 hint(bsoncxx::v_noabi::document::view_or_value index) : _index_doc{std::move(index)} {}
70
77 explicit hint(bsoncxx::v_noabi::string::view_or_value index) : _index_string(std::move(index)) {}
78
86 friend bool operator==(hint const& index_hint, std::string index) {
87 return index_hint._index_string == index;
88 }
89
97 friend bool operator==(hint const& index_hint, bsoncxx::v_noabi::document::view index) {
98 return index_hint._index_doc == index;
99 }
100
108 if (_index_doc) {
110 }
111
113 }
114
122 return this->to_value();
123 }
124
125 private:
128};
129
136
138inline bool operator==(std::string str, hint const& hint) {
139 return hint == str;
140}
141
143inline bool operator!=(hint const& hint, std::string str) {
144 return !(hint == str);
145}
146
148inline bool operator!=(std::string str, hint const& hint) {
149 return !(hint == str);
150}
151
154
161
164 return hint == doc;
165}
166
169 return !(hint == doc);
170}
171
174 return !(hint == doc);
175}
176
179
184 return {std::move(v)};
185}
186
190inline v1::hint to_v1(v_noabi::hint const& v) {
191 return v1::hint{v};
192}
193
194} // namespace v_noabi
195} // namespace mongocxx
196
197namespace mongocxx {
198
199using v_noabi::operator==;
200using v_noabi::operator!=;
201
202} // namespace mongocxx
203
205
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
hint(v1::hint hint)
Construct with the mongocxx::v1 equivalent.
Options related to a MongoDB query hint.
Definition hint.hpp:47
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
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
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
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
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
bsoncxx::v_noabi::types::view to_value() const
Returns a bsoncxx::v_noabi::types::view representing this hint.
Definition hint.hpp:107
bool operator!=(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:148
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
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
hint(bsoncxx::v_noabi::document::view_or_value index)
Constructs a new hint.
Definition hint.hpp:69
friend bool operator==(hint const &index_hint, std::string index)
Convenience methods to compare for equality against an index name.
Definition hint.hpp:86
hint(v1::hint hint)
Construct with the mongocxx::v1 equivalent.
hint(bsoncxx::v_noabi::string::view_or_value index)
Constructs a new hint.
Definition hint.hpp:77
Provides bsoncxx::v_noabi::document::view_or_value.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
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
v_noabi::types::bson_value::view view
Equivalent to bsoncxx::v_noabi::types::bson_value::view.
Definition view-fwd.hpp:35
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
A BSON document value.
Definition types.hpp:211
A BSON UTF-8 encoded string value.
Definition types.hpp:177
Provides entities used to represent BSON types.
Provides mongocxx::v1::hint.
Provides bsoncxx::v_noabi::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Equivalent to bsoncxx/types/bson_value/view.hpp.
Declares mongocxx::v_noabi::hint.