Skip to content

Commit 0e17103

Browse files
authored
CXX-2745 relocate top-level dependencies into v1 headers (#1318)
* format: add v1 header groups * Fix library name in mongocxx doc.hpp * v1: add config, detail, and stdx headers * v1: add BSONCXX_VERSION_STRING * Use consistent prefix for private macros used in public headers * Move comparison-related type traits into type_traits.hpp
1 parent b0686db commit 0e17103

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3437
-2318
lines changed

.clang-format

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ AttributeMacros:
8383
- BSONCXX_ABI_NO_EXPORT
8484
- BSONCXX_DEPRECATED
8585
- BSONCXX_ENUM
86-
- BSONCXX_PRAGMA
87-
- BSONCXX_RETURNS
86+
- BSONCXX_PRIVATE_PRAGMA
87+
- BSONCXX_PRIVATE_RETURNS
8888
- MONGOCXX_ABI_CDECL
8989
- MONGOCXX_ABI_EXPORT
9090
- MONGOCXX_ABI_NO_EXPORT
@@ -144,24 +144,40 @@ IncludeBlocks: Regroup
144144
IncludeCategories:
145145
- Regex: '".*"' # relative headers
146146
Priority: 10
147+
- Regex: 'bsoncxx/v1/.*/prelude\.hpp' # v1 preludes
148+
Priority: 20
149+
- Regex: 'mongocxx/v1/.*/prelude\.hpp' # v1 preludes
150+
Priority: 21
151+
- Regex: 'bsoncxx/v1/.*(-|\/)fwd\.hpp' # v1 forward headers
152+
Priority: 22
153+
- Regex: 'mongocxx/v1/.*(-|\/)fwd\.hpp' # v1 forward headers
154+
Priority: 23
155+
- Regex: 'bsoncxx/v1/.*\.hpp' # v1 public headers
156+
Priority: 24
157+
- Regex: 'mongocxx/v1/.*\.hpp' # v1 public headers
158+
Priority: 25
159+
- Regex: 'bsoncxx/v1/.*\.hh' # v1 private headers
160+
Priority: 26
161+
- Regex: 'mongocxx/v1/.*\.hh' # v1 private headers
162+
Priority: 27
147163
- Regex: 'bsoncxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
148-
Priority: 50
164+
Priority: 60
149165
- Regex: 'mongocxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
150-
Priority: 51
166+
Priority: 61
151167
- Regex: 'bsoncxx/test/.*' # test headers
152-
Priority: 60
168+
Priority: 70
153169
- Regex: 'mongocxx/test/.*' # test headers
154-
Priority: 61
170+
Priority: 71
155171
- Regex: '<[[:alnum:]_.]+>' # system headers
156-
Priority: 20
157-
- Regex: 'bsoncxx/.*(-|\/)fwd\.(hpp|hh)' # all driver forwarding headers
158172
Priority: 30
159-
- Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all driver forwarding headers
160-
Priority: 31
161-
- Regex: 'bsoncxx/.*' # all remaining (normal) driver headers
173+
- Regex: 'bsoncxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers
162174
Priority: 40
163-
- Regex: 'mongocxx/.*' # all remaining (normal) driver headers
175+
- Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers
164176
Priority: 41
177+
- Regex: 'bsoncxx/.*' # all remaining headers
178+
Priority: 50
179+
- Regex: 'mongocxx/.*' # all remaining headers
180+
Priority: 51
165181
- Regex: '.*' # all other headers (third party)
166182
Priority: 90
167183
IncludeIsMainRegex: '([-_](test|unittest))?$'
@@ -274,14 +290,14 @@ SpacesInSquareBrackets: false
274290
Standard: Cpp11
275291
StatementAttributeLikeMacros: []
276292
StatementMacros:
277-
- BSONCXX_DISABLE_WARNING
278-
- BSONCXX_FORCE_SEMICOLON
279-
- BSONCXX_IF_CLANG
280-
- BSONCXX_IF_GCC
281-
- BSONCXX_IF_GNU_LIKE
282-
- BSONCXX_IF_MSVC
283-
- BSONCXX_POP_WARNINGS
284-
- BSONCXX_PUSH_WARNINGS
293+
- BSONCXX_PRIVATE_FORCE_SEMICOLON
294+
- BSONCXX_PRIVATE_IF_CLANG
295+
- BSONCXX_PRIVATE_IF_GCC
296+
- BSONCXX_PRIVATE_IF_GNU_LIKE
297+
- BSONCXX_PRIVATE_IF_MSVC
298+
- BSONCXX_PRIVATE_WARNINGS_DISABLE
299+
- BSONCXX_PRIVATE_WARNINGS_POP
300+
- BSONCXX_PRIVATE_WARNINGS_PUSH
285301
- BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
286302
- BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
287303
TableGenBreakInsideDAGArg: DontBreak

examples/bsoncxx/getting_values.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int EXAMPLES_CDECL main() {
7272
auto invalid1 = doc["name"]["middle"];
7373
auto invalid2 = doc["contribs"][1000];
7474
if (invalid1 || invalid2) {
75-
BSONCXX_UNREACHABLE; // Not reached.
75+
return EXIT_FAILURE; // Not reached.
7676
}
7777

7878
// Similarly, indexed access (either by string or numeric index) into a type that is not
@@ -81,7 +81,7 @@ int EXAMPLES_CDECL main() {
8181
auto invalid3 = doc["_id"]["invalid"];
8282
auto invalid4 = doc["name"][3];
8383
if (invalid3 || invalid4) {
84-
BSONCXX_UNREACHABLE; // Not reached.
84+
return EXIT_FAILURE; // Not reached.
8585
}
8686

8787
// Values are accessed through get_*() methods.

src/bsoncxx/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ if(1)
192192
BASE_NAME BSONCXX_ABI
193193
EXPORT_MACRO_NAME BSONCXX_ABI_EXPORT
194194
DEPRECATED_MACRO_NAME BSONCXX_DEPRECATED
195-
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/bsoncxx/v_noabi/bsoncxx/config/export.hpp
195+
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/bsoncxx/v1/config/export.hpp
196196
STATIC_DEFINE BSONCXX_STATIC
197197
CUSTOM_CONTENT_FROM_VARIABLE bsoncxx_export_header_custom_content
198198
)
199199

200200
install(FILES
201-
${PROJECT_BINARY_DIR}/lib/bsoncxx/v_noabi/bsoncxx/config/export.hpp
202-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v_noabi/bsoncxx/config
201+
${PROJECT_BINARY_DIR}/lib/bsoncxx/v1/config/export.hpp
202+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bsoncxx/v1/config
203203
COMPONENT dev
204204
)
205205
endfunction()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#if !defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
16+
#error "This file is for documentation purposes only. It should not be included."
17+
#endif // !defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
18+
19+
///
20+
/// @file
21+
/// For documentation purposes only.
22+
///
23+
/// @note This header is not includable!
24+
///
25+
26+
///
27+
/// @dir bsoncxx/v1
28+
/// Provides headers declaring entities in @ref bsoncxx::v1.
29+
///
30+
31+
///
32+
/// @dir bsoncxx/v1/config
33+
/// Provides headers related to bsoncxx library configuration.
34+
///
35+
36+
///
37+
/// @dir bsoncxx/v1/detail
38+
/// Provides headers for internal use only.
39+
///
40+
/// @warning For internal use only!
41+
///
42+
43+
///
44+
/// @dir bsoncxx/v1/stdx
45+
/// Provides headers declaring entities in @ref bsoncxx::v1::stdx.
46+
///
47+
48+
///
49+
/// @namespace bsoncxx::v1
50+
/// Declares entities whose ABI stability is guaranteed for documented symbols.
51+
///
52+
53+
///
54+
/// @namespace bsoncxx::v1::stdx
55+
/// @copydoc bsoncxx::stdx
56+
///

src/bsoncxx/include/bsoncxx/docs/v_noabi.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525

2626
///
2727
/// @dir bsoncxx/v_noabi
28-
/// The directory relative to which headers declaring entities in @ref bsoncxx::v_noabi are
29-
/// typically included.
28+
/// Provides headers declaring entities in @ref bsoncxx::v_noabi.
3029
///
31-
/// For backward compatibility, unstable ABI headers may be included using the syntax
32-
/// `<bsoncxx/foo.hpp>`, which is equivalent to `<bsoncxx/v_noabi/bsoncxx/foo.hpp>`.
30+
/// Unstable ABI headers may be included using the syntax `<bsoncxx/foo.hpp>`, which is equivalent to
31+
/// `<bsoncxx/v_noabi/bsoncxx/foo.hpp>`.
3332
///
3433

3534
///
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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 <bsoncxx/v1/detail/prelude.hpp>
18+
19+
#include <bsoncxx/v1/detail/macros.hpp>
20+
#include <bsoncxx/v1/detail/type_traits.hpp>
21+
22+
#include <cstddef>
23+
#include <functional>
24+
#include <type_traits>
25+
26+
namespace bsoncxx {
27+
namespace detail {
28+
29+
// Callable object and tag type for equality comparison.
30+
struct equal_to {
31+
template <typename L, typename R>
32+
constexpr requires_t<bool, is_equality_comparable<L, R>> operator()(L&& l, R&& r) const noexcept(noexcept(l == r)) {
33+
return l == r;
34+
}
35+
};
36+
37+
// Derive from this class to define ADL-only operator== and operator!= on the basis of
38+
// an ADL-only tag_invoke(equal_to, l, r).
39+
class equality_operators {
40+
template <typename L, typename R>
41+
constexpr static auto impl(rank<1>, L& l, R& r) BSONCXX_PRIVATE_RETURNS(tag_invoke(equal_to{}, l, r));
42+
43+
template <typename L, typename R>
44+
constexpr static auto impl(rank<0>, L& l, R& r) BSONCXX_PRIVATE_RETURNS(tag_invoke(equal_to{}, r, l));
45+
46+
// @cond DOXYGEN_DISABLE "Found ';' while parsing initializer list!"
47+
template <typename Left, typename Other>
48+
constexpr friend auto operator==(Left const& self, Other const& other)
49+
BSONCXX_PRIVATE_RETURNS(equality_operators::impl(rank<1>{}, self, other));
50+
// @endcond
51+
52+
// @cond DOXYGEN_DISABLE "Found ';' while parsing initializer list!"
53+
template <typename Left, typename Other>
54+
constexpr friend auto operator!=(Left const& self, Other const& other)
55+
BSONCXX_PRIVATE_RETURNS(!equality_operators::impl(rank<1>{}, self, other));
56+
// @endcond
57+
};
58+
59+
// Very basic impl of C++20 std::strong_ordering.
60+
//
61+
// We don't need other weaker orderings yet, so this is all that we have.
62+
class strong_ordering {
63+
signed char _c;
64+
struct _construct {};
65+
66+
constexpr strong_ordering(_construct, signed char c) noexcept : _c(c) {}
67+
68+
public:
69+
static strong_ordering const less;
70+
static strong_ordering const greater;
71+
static strong_ordering const equivalent;
72+
static strong_ordering const equal;
73+
74+
constexpr strong_ordering(std::nullptr_t) noexcept : strong_ordering(_construct{}, 0) {}
75+
76+
constexpr bool operator==(strong_ordering o) const noexcept {
77+
return _c == o._c;
78+
}
79+
constexpr bool operator!=(strong_ordering o) const noexcept {
80+
return !(*this == o);
81+
}
82+
#pragma push_macro("DEFOP")
83+
#undef DEFOP
84+
#define DEFOP(Op) \
85+
constexpr bool operator Op(std::nullptr_t) const noexcept { \
86+
return _c Op 0; \
87+
} \
88+
static_assert(true, "")
89+
DEFOP(<);
90+
DEFOP(>);
91+
DEFOP(<=);
92+
DEFOP(>=);
93+
#pragma pop_macro("DEFOP")
94+
95+
// nonstd: Swap greater/less values
96+
constexpr strong_ordering inverted() const noexcept {
97+
return *this < nullptr ? greater : *this > nullptr ? less : *this;
98+
}
99+
};
100+
101+
#pragma push_macro("INLINE_VAR")
102+
#undef INLINE_VAR
103+
#define INLINE_VAR \
104+
BSONCXX_PRIVATE_IF_GNU_LIKE([[gnu::weak]]) \
105+
BSONCXX_PRIVATE_IF_MSVC(__declspec(selectany))
106+
107+
INLINE_VAR const strong_ordering strong_ordering::less = strong_ordering(strong_ordering::_construct{}, -1);
108+
INLINE_VAR const strong_ordering strong_ordering::greater = strong_ordering(strong_ordering::_construct{}, 1);
109+
INLINE_VAR const strong_ordering strong_ordering::equivalent = strong_ordering(strong_ordering::_construct{}, 0);
110+
INLINE_VAR const strong_ordering strong_ordering::equal = strong_ordering(strong_ordering::_construct{}, 0);
111+
112+
#pragma pop_macro("INLINE_VAR")
113+
114+
// Implements a three-way comparison between two objects. That is, in
115+
// a single operation, determine whether the left operand is less-than, greater-than,
116+
// or equal-to the right-hand operand.
117+
struct compare_three_way {
118+
BSONCXX_PRIVATE_WARNINGS_PUSH();
119+
BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wfloat-equal"));
120+
template <
121+
typename L,
122+
typename R,
123+
typename = decltype(std::declval<L>() < std::declval<R>()),
124+
typename = decltype(std::declval<L>() == std::declval<R>())>
125+
constexpr static strong_ordering impl(L const& l, R const& r, rank<1>) {
126+
return (l < r) ? strong_ordering::less : (l == r ? strong_ordering::equal : strong_ordering::greater);
127+
}
128+
BSONCXX_PRIVATE_WARNINGS_POP();
129+
130+
template <
131+
typename L,
132+
typename R,
133+
typename = decltype(tag_invoke(std::declval<compare_three_way>(), std::declval<L>(), std::declval<R>()))>
134+
constexpr static strong_ordering impl(L const& l, R const& r, rank<2>) {
135+
return tag_invoke(compare_three_way{}, l, r);
136+
}
137+
138+
template <typename L, typename R>
139+
constexpr auto operator()(L const& l, R const& r) const BSONCXX_PRIVATE_RETURNS((impl)(l, r, rank<2>{}));
140+
};
141+
142+
// Inherit to define ADL-visible ordering operators based on an ADL-visible
143+
// implementation of tag_invoke(compare_three_way, l, r).
144+
struct ordering_operators {
145+
template <typename L, typename R>
146+
constexpr static auto impl(L const& l, R const& r, rank<1>)
147+
BSONCXX_PRIVATE_RETURNS(tag_invoke(compare_three_way{}, l, r));
148+
149+
template <typename L, typename R>
150+
constexpr static auto impl(L const& l, R const& r, rank<0>)
151+
BSONCXX_PRIVATE_RETURNS(tag_invoke(compare_three_way{}, r, l).inverted());
152+
153+
#pragma push_macro("DEFOP")
154+
#undef DEFOP
155+
#define DEFOP(Oper) \
156+
template <typename L, typename R> \
157+
constexpr friend auto operator Oper(L const& l, R const& r) \
158+
BSONCXX_PRIVATE_RETURNS(ordering_operators::impl(l, r, rank<1>{}) Oper nullptr)
159+
DEFOP(<);
160+
DEFOP(>);
161+
DEFOP(<=);
162+
DEFOP(>=);
163+
#pragma pop_macro("DEFOP")
164+
};
165+
166+
} // namespace detail
167+
} // namespace bsoncxx
168+
169+
#include <bsoncxx/v1/detail/postlude.hpp>
170+
171+
///
172+
/// @file
173+
/// For internal use only!
174+
///
175+
/// @warning For internal use only!
176+
///

0 commit comments

Comments
 (0)