1414
1515#pragma once
1616
17- #include < string>
18-
1917#include < mongocxx/hint-fwd.hpp> // IWYU pragma: export
2018
19+ //
20+
21+ #include < mongocxx/v1/hint.hpp> // IWYU pragma: export
22+
23+ #include < string>
24+ #include < utility>
25+
2126#include < bsoncxx/document/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
27+ #include < bsoncxx/document/view.hpp>
2228#include < bsoncxx/document/view_or_value.hpp>
23- #include < bsoncxx/stdx/optional.hpp>
29+ #include < bsoncxx/stdx/optional.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
2430#include < bsoncxx/string/view_or_value.hpp>
25- #include < bsoncxx/types/bson_value/view.hpp>
31+ #include < bsoncxx/types.hpp>
32+ #include < bsoncxx/types/view.hpp>
2633
2734#include < mongocxx/config/prelude.hpp>
2835
@@ -34,6 +41,22 @@ namespace v_noabi {
3441// /
3542class hint {
3643 public:
44+ // /
45+ // / Construct with the @ref mongocxx::v1 equivalent.
46+ // /
47+ /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() hint(v1::hint hint);
48+
49+ // /
50+ // / Convert to the @ref mongocxx::v1 equivalent.
51+ // /
52+ explicit operator v1::hint () const {
53+ if (_index_doc) {
54+ return v1::hint{bsoncxx::v1::document::value{bsoncxx::v_noabi::to_v1 (_index_doc->view ())}};
55+ }
56+
57+ return v1::hint{std::string{_index_string->view ()}};
58+ }
59+
3760 // /
3861 // / Constructs a new hint.
3962 // /
@@ -43,15 +66,15 @@ class hint {
4366 // / @param index
4467 // / Document view or value representing the index to be used.
4568 // /
46- MONGOCXX_ABI_EXPORT_CDECL () hint(bsoncxx::v_noabi::document::view_or_value index);
69+ hint (bsoncxx::v_noabi::document::view_or_value index) : _index_doc{ std::move (index)} {}
4770
4871 // /
4972 // / Constructs a new hint.
5073 // /
5174 // / @param index
5275 // / String representing the name of the index to be used.
5376 // /
54- explicit MONGOCXX_ABI_EXPORT_CDECL () hint(bsoncxx::v_noabi::string::view_or_value index);
77+ explicit hint (bsoncxx::v_noabi::string::view_or_value index) : _index_string(std::move(index)) {}
5578
5679 // /
5780 // / @relates mongocxx::v_noabi::hint
@@ -60,7 +83,9 @@ class hint {
6083 // /
6184 // / Compares equal if the hint contains a matching index name. Otherwise, compares unequal.
6285 // /
63- friend MONGOCXX_ABI_EXPORT_CDECL (bool ) operator==(hint const & index_hint, std::string index);
86+ friend bool operator ==(hint const & index_hint, std::string index) {
87+ return index_hint._index_string == index;
88+ }
6489
6590 // /
6691 // / @relates mongocxx::v_noabi::hint
@@ -69,26 +94,32 @@ class hint {
6994 // /
7095 // / Compares equal if the hint contains a matching index document. Otherwise, compares unequal.
7196 // /
72- friend MONGOCXX_ABI_EXPORT_CDECL (bool ) operator==(hint const & index_hint, bsoncxx::v_noabi::document::view index);
97+ friend bool operator ==(hint const & index_hint, bsoncxx::v_noabi::document::view index) {
98+ return index_hint._index_doc == index;
99+ }
73100
74101 // /
75- // / Returns a types::bson_value ::view representing this hint.
102+ // / Returns a @ref bsoncxx::v_noabi::types ::view representing this hint.
76103 // /
77- // / @return Hint, as a types::bson_value::view. The caller must ensure that the returned object
78- // / not outlive
79- // / the hint object that it was created from.
104+ // / @return Hint, as a @ref bsoncxx::v_noabi::types::view. The caller must ensure that the returned object not
105+ // / outlive the hint object that it was created from.
80106 // /
81- MONGOCXX_ABI_EXPORT_CDECL (bsoncxx::v_noabi::types::bson_value::view) to_value() const ;
107+ bsoncxx::v_noabi::types::view to_value () const {
108+ if (_index_doc) {
109+ return bsoncxx::v_noabi::types::view{bsoncxx::v_noabi::types::b_document{_index_doc->view ()}};
110+ }
111+
112+ return bsoncxx::v_noabi::types::view{bsoncxx::v_noabi::types::b_string{_index_string->view ()}};
113+ }
82114
83115 // /
84- // / Returns a types::bson_value ::view representing this hint.
116+ // / Returns a @ref bsoncxx::v_noabi::types ::view representing this hint.
85117 // /
86- // / @return Hint, as a types::bson_value::view. The caller must ensure that the returned object
87- // / not outlive
88- // / the hint object that it was created from.
118+ // / @return Hint, as a @ref bsoncxx::v_noabi::types::view. The caller must ensure that the returned object not
119+ // / outlive the hint object that it was created from.
89120 // /
90- operator bsoncxx::v_noabi::types::bson_value:: view () const {
91- return to_value ();
121+ operator bsoncxx::v_noabi::types::view () const {
122+ return this -> to_value ();
92123 }
93124
94125 private:
@@ -104,13 +135,19 @@ class hint {
104135// / @{
105136
106137// / @relatesalso mongocxx::v_noabi::hint
107- MONGOCXX_ABI_EXPORT_CDECL (bool ) operator ==(std::string index, hint const & index_hint);
138+ inline bool operator ==(std::string str, hint const & hint) {
139+ return hint == str;
140+ }
108141
109142// / @relatesalso mongocxx::v_noabi::hint
110- MONGOCXX_ABI_EXPORT_CDECL (bool ) operator !=(hint const & index_hint, std::string index);
143+ inline bool operator !=(hint const & hint, std::string str) {
144+ return !(hint == str);
145+ }
111146
112147// / @relatesalso mongocxx::v_noabi::hint
113- MONGOCXX_ABI_EXPORT_CDECL (bool ) operator !=(std::string index, hint const & index_index);
148+ inline bool operator !=(std::string str, hint const & hint) {
149+ return !(hint == str);
150+ }
114151
115152// / @}
116153// /
@@ -123,25 +160,44 @@ MONGOCXX_ABI_EXPORT_CDECL(bool) operator!=(std::string index, hint const& index_
123160// / @{
124161
125162// / @relatesalso mongocxx::v_noabi::hint
126- MONGOCXX_ABI_EXPORT_CDECL (bool )
127- operator ==(bsoncxx::v_noabi::document::view index, hint const & index_hint);
163+ inline bool operator ==(bsoncxx::v_noabi::document::view doc, hint const & hint) {
164+ return hint == doc;
165+ }
166+
128167// / @relatesalso mongocxx::v_noabi::hint
129- MONGOCXX_ABI_EXPORT_CDECL (bool )
130- operator !=(hint const & index_hint, bsoncxx::v_noabi::document::view index);
168+ inline bool operator !=(hint const & hint, bsoncxx::v_noabi::document::view doc) {
169+ return !(hint == doc);
170+ }
171+
131172// / @relatesalso mongocxx::v_noabi::hint
132- MONGOCXX_ABI_EXPORT_CDECL (bool )
133- operator !=(bsoncxx::v_noabi::document::view index, hint const & index_hint);
173+ inline bool operator !=(bsoncxx::v_noabi::document::view doc, hint const & hint) {
174+ return !(hint == doc);
175+ }
134176
135177// / @}
136178// /
137179
180+ // /
181+ // / Convert to the @ref mongocxx::v_noabi equivalent of `v`.
182+ // /
183+ inline v_noabi::hint from_v1 (v1::hint v) {
184+ return {std::move (v)};
185+ }
186+
187+ // /
188+ // / Convert to the @ref mongocxx::v1 equivalent of `v`.
189+ // /
190+ inline v1::hint to_v1 (v_noabi::hint const & v) {
191+ return v1::hint{v};
192+ }
193+
138194} // namespace v_noabi
139195} // namespace mongocxx
140196
141197namespace mongocxx {
142198
143- using ::mongocxx:: v_noabi::operator ==;
144- using ::mongocxx:: v_noabi::operator !=;
199+ using v_noabi::operator ==;
200+ using v_noabi::operator !=;
145201
146202} // namespace mongocxx
147203
@@ -151,3 +207,6 @@ using ::mongocxx::v_noabi::operator!=;
151207// / @file
152208// / Provides @ref mongocxx::v_noabi::hint.
153209// /
210+ // / @par Includes
211+ // / - @ref mongocxx/v1/hint.hpp
212+ // /
0 commit comments