Skip to content

Commit 8587a87

Browse files
authored
CXX-2288 Add forward headers for bsoncxx and mongocxx (#1061)
* Add forward headers to clang-format rules * Add forward headers for bsoncxx and mongocxx * Make using namespace declaration in list.hpp VERY noticable * Ensure headers provide the definitive declaration for all entities (no rogue forward declarations). * Use simple-type-specifier form for friend class declarations
1 parent 5bdf573 commit 8587a87

File tree

303 files changed

+4886
-862
lines changed

Some content is hidden

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

303 files changed

+4886
-862
lines changed

.clang-format

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ Cpp11BracedListStyle: true
99
DerivePointerAlignment: false
1010
IncludeBlocks: Regroup
1111
IncludeCategories:
12-
- Regex: 'prelude\.(hpp|hh)' # preludes
13-
Priority: 3
14-
- Regex: '<[[:alnum:]_.]+>' # system headers
12+
- Regex: 'prelude\.(hpp|hh)' # preludes
13+
Priority: 4
14+
- Regex: '<[[:alnum:]_.]+>' # system headers
1515
Priority: 1
16-
- Regex: '.*' # driver headers
16+
- Regex: '.*(-|\/)fwd\.(hpp|hh)' # forwarding headers
1717
Priority: 2
18+
- Regex: '.*' # driver headers
19+
Priority: 3
1820
IndentWidth: 4
1921
MaxEmptyLinesToKeep: 1
2022
NamespaceIndentation: None

src/bsoncxx/include/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,87 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
2020

2121
set_dist_list(src_bsoncxx_include_DIST
2222
CMakeLists.txt
23+
bsoncxx/v_noabi/bsoncxx/array/element-fwd.hpp
2324
bsoncxx/v_noabi/bsoncxx/array/element.hpp
25+
bsoncxx/v_noabi/bsoncxx/array/value-fwd.hpp
2426
bsoncxx/v_noabi/bsoncxx/array/value.hpp
2527
bsoncxx/v_noabi/bsoncxx/array/view_or_value.hpp
28+
bsoncxx/v_noabi/bsoncxx/array/view-fwd.hpp
2629
bsoncxx/v_noabi/bsoncxx/array/view.hpp
30+
bsoncxx/v_noabi/bsoncxx/builder/basic/array-fwd.hpp
2731
bsoncxx/v_noabi/bsoncxx/builder/basic/array.hpp
32+
bsoncxx/v_noabi/bsoncxx/builder/basic/document-fwd.hpp
2833
bsoncxx/v_noabi/bsoncxx/builder/basic/document.hpp
2934
bsoncxx/v_noabi/bsoncxx/builder/basic/helpers.hpp
3035
bsoncxx/v_noabi/bsoncxx/builder/basic/impl.hpp
3136
bsoncxx/v_noabi/bsoncxx/builder/basic/kvp.hpp
37+
bsoncxx/v_noabi/bsoncxx/builder/basic/sub_array-fwd.hpp
3238
bsoncxx/v_noabi/bsoncxx/builder/basic/sub_array.hpp
39+
bsoncxx/v_noabi/bsoncxx/builder/basic/sub_document-fwd.hpp
3340
bsoncxx/v_noabi/bsoncxx/builder/basic/sub_document.hpp
41+
bsoncxx/v_noabi/bsoncxx/builder/concatenate-fwd.hpp
3442
bsoncxx/v_noabi/bsoncxx/builder/concatenate.hpp
43+
bsoncxx/v_noabi/bsoncxx/builder/core-fwd.hpp
3544
bsoncxx/v_noabi/bsoncxx/builder/core.hpp
45+
bsoncxx/v_noabi/bsoncxx/builder/list-fwd.hpp
3646
bsoncxx/v_noabi/bsoncxx/builder/list.hpp
47+
bsoncxx/v_noabi/bsoncxx/builder/stream/array_context-fwd.hpp
3748
bsoncxx/v_noabi/bsoncxx/builder/stream/array_context.hpp
49+
bsoncxx/v_noabi/bsoncxx/builder/stream/array-fwd.hpp
3850
bsoncxx/v_noabi/bsoncxx/builder/stream/array.hpp
51+
bsoncxx/v_noabi/bsoncxx/builder/stream/closed_context-fwd.hpp
3952
bsoncxx/v_noabi/bsoncxx/builder/stream/closed_context.hpp
53+
bsoncxx/v_noabi/bsoncxx/builder/stream/document-fwd.hpp
4054
bsoncxx/v_noabi/bsoncxx/builder/stream/document.hpp
55+
bsoncxx/v_noabi/bsoncxx/builder/stream/helpers-fwd.hpp
4156
bsoncxx/v_noabi/bsoncxx/builder/stream/helpers.hpp
57+
bsoncxx/v_noabi/bsoncxx/builder/stream/key_context-fwd.hpp
4258
bsoncxx/v_noabi/bsoncxx/builder/stream/key_context.hpp
59+
bsoncxx/v_noabi/bsoncxx/builder/stream/single_context-fwd.hpp
4360
bsoncxx/v_noabi/bsoncxx/builder/stream/single_context.hpp
61+
bsoncxx/v_noabi/bsoncxx/builder/stream/value_context-fwd.hpp
4462
bsoncxx/v_noabi/bsoncxx/builder/stream/value_context.hpp
4563
bsoncxx/v_noabi/bsoncxx/config/compiler.hpp
4664
bsoncxx/v_noabi/bsoncxx/config/postlude.hpp
4765
bsoncxx/v_noabi/bsoncxx/config/prelude.hpp
66+
bsoncxx/v_noabi/bsoncxx/decimal128-fwd.hpp
4867
bsoncxx/v_noabi/bsoncxx/decimal128.hpp
68+
bsoncxx/v_noabi/bsoncxx/document/element-fwd.hpp
4969
bsoncxx/v_noabi/bsoncxx/document/element.hpp
70+
bsoncxx/v_noabi/bsoncxx/document/value-fwd.hpp
5071
bsoncxx/v_noabi/bsoncxx/document/value.hpp
5172
bsoncxx/v_noabi/bsoncxx/document/view_or_value.hpp
73+
bsoncxx/v_noabi/bsoncxx/document/view-fwd.hpp
5274
bsoncxx/v_noabi/bsoncxx/document/view.hpp
5375
bsoncxx/v_noabi/bsoncxx/enums/binary_sub_type.hpp
5476
bsoncxx/v_noabi/bsoncxx/enums/type.hpp
77+
bsoncxx/v_noabi/bsoncxx/exception/error_code-fwd.hpp
5578
bsoncxx/v_noabi/bsoncxx/exception/error_code.hpp
79+
bsoncxx/v_noabi/bsoncxx/exception/exception-fwd.hpp
5680
bsoncxx/v_noabi/bsoncxx/exception/exception.hpp
81+
bsoncxx/v_noabi/bsoncxx/json-fwd.hpp
5782
bsoncxx/v_noabi/bsoncxx/json.hpp
83+
bsoncxx/v_noabi/bsoncxx/oid-fwd.hpp
5884
bsoncxx/v_noabi/bsoncxx/oid.hpp
5985
bsoncxx/v_noabi/bsoncxx/stdx/make_unique.hpp
6086
bsoncxx/v_noabi/bsoncxx/stdx/optional.hpp
6187
bsoncxx/v_noabi/bsoncxx/stdx/string_view.hpp
6288
bsoncxx/v_noabi/bsoncxx/stdx/type_traits.hpp
6389
bsoncxx/v_noabi/bsoncxx/string/to_string.hpp
90+
bsoncxx/v_noabi/bsoncxx/string/view_or_value-fwd.hpp
6491
bsoncxx/v_noabi/bsoncxx/string/view_or_value.hpp
92+
bsoncxx/v_noabi/bsoncxx/types-fwd.hpp
6593
bsoncxx/v_noabi/bsoncxx/types.hpp
6694
bsoncxx/v_noabi/bsoncxx/types/bson_value/make_value.hpp
95+
bsoncxx/v_noabi/bsoncxx/types/bson_value/value-fwd.hpp
6796
bsoncxx/v_noabi/bsoncxx/types/bson_value/value.hpp
6897
bsoncxx/v_noabi/bsoncxx/types/bson_value/view_or_value.hpp
98+
bsoncxx/v_noabi/bsoncxx/types/bson_value/view-fwd.hpp
6999
bsoncxx/v_noabi/bsoncxx/types/bson_value/view.hpp
70100
bsoncxx/v_noabi/bsoncxx/types/value.hpp
71101
bsoncxx/v_noabi/bsoncxx/util/functor.hpp
102+
bsoncxx/v_noabi/bsoncxx/validate-fwd.hpp
72103
bsoncxx/v_noabi/bsoncxx/validate.hpp
104+
bsoncxx/v_noabi/bsoncxx/view_or_value-fwd.hpp
73105
bsoncxx/v_noabi/bsoncxx/view_or_value.hpp
74106
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 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/config/prelude.hpp>
18+
19+
namespace bsoncxx {
20+
inline namespace v_noabi {
21+
namespace array {
22+
23+
class BSONCXX_API element;
24+
25+
} // namespace array
26+
} // namespace v_noabi
27+
} // namespace bsoncxx
28+
29+
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/element.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
#include <cstddef>
1818
#include <cstdint>
1919

20+
#include <bsoncxx/array/element-fwd.hpp>
21+
#include <bsoncxx/array/view-fwd.hpp>
22+
#include <bsoncxx/types/bson_value/view-fwd.hpp>
23+
2024
#include <bsoncxx/document/element.hpp>
2125

2226
#include <bsoncxx/config/prelude.hpp>
2327

2428
namespace bsoncxx {
2529
inline namespace v_noabi {
26-
namespace types {
27-
namespace bson_value {
28-
class view;
29-
} // namespace bson_value
30-
} // namespace types
31-
3230
namespace array {
3331

3432
///
@@ -38,7 +36,7 @@ namespace array {
3836
/// interrogated by calling type() and a specific value can be extracted through
3937
/// get_X() accessors.
4038
///
41-
class BSONCXX_API element : private document::element {
39+
class element : private document::element {
4240
public:
4341
element();
4442

@@ -80,7 +78,7 @@ class BSONCXX_API element : private document::element {
8078
using document::element::raw;
8179

8280
private:
83-
friend class view;
81+
friend ::bsoncxx::v_noabi::array::view;
8482

8583
BSONCXX_PRIVATE explicit element(const std::uint8_t* raw,
8684
std::uint32_t length,
@@ -121,7 +119,6 @@ BSONCXX_API bool BSONCXX_CALL operator!=(const types::bson_value::view& v, const
121119
///
122120

123121
} // namespace array
124-
125122
} // namespace v_noabi
126123
} // namespace bsoncxx
127124

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 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/config/prelude.hpp>
18+
19+
namespace bsoncxx {
20+
inline namespace v_noabi {
21+
namespace array {
22+
23+
class BSONCXX_API value;
24+
25+
} // namespace array
26+
} // namespace v_noabi
27+
} // namespace bsoncxx
28+
29+
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/value.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <cstdlib>
1818
#include <memory>
1919

20+
#include <bsoncxx/array/value-fwd.hpp>
21+
2022
#include <bsoncxx/array/view.hpp>
2123
#include <bsoncxx/document/value.hpp>
2224

@@ -31,7 +33,7 @@ namespace array {
3133
/// out of scope, the underlying buffer is freed. Generally this class should be used
3234
/// sparingly; array::view should be used instead wherever possible.
3335
///
34-
class BSONCXX_API value {
36+
class value {
3537
public:
3638
using deleter_type = void (*)(std::uint8_t*);
3739
using unique_ptr_type = std::unique_ptr<uint8_t[], deleter_type>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2023 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/config/prelude.hpp>
18+
19+
namespace bsoncxx {
20+
inline namespace v_noabi {
21+
namespace array {
22+
23+
class BSONCXX_API view;
24+
25+
} // namespace array
26+
} // namespace v_noabi
27+
} // namespace bsoncxx
28+
29+
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/array/view.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,22 @@
1818
#include <cstdint>
1919
#include <iterator>
2020

21+
#include <bsoncxx/array/view-fwd.hpp>
22+
#include <bsoncxx/types/bson_value/view-fwd.hpp>
23+
2124
#include <bsoncxx/array/element.hpp>
2225
#include <bsoncxx/document/view.hpp>
2326

2427
#include <bsoncxx/config/prelude.hpp>
2528

2629
namespace bsoncxx {
2730
inline namespace v_noabi {
28-
namespace types {
29-
namespace bson_value {
30-
class view;
31-
} // namespace bson_value
32-
} // namespace types
33-
3431
namespace array {
3532

3633
///
3734
/// A read-only, non-owning view of a BSON document.
3835
///
39-
class BSONCXX_API view {
36+
class view {
4037
public:
4138
class BSONCXX_API const_iterator;
4239
using iterator = const_iterator;
@@ -155,7 +152,7 @@ class BSONCXX_API view {
155152
/// This iterator type provides a const forward iterator interface to array
156153
/// view elements.
157154
///
158-
class BSONCXX_API view::const_iterator {
155+
class view::const_iterator {
159156
public:
160157
///
161158
/// std::iterator_traits
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023 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+
namespace bsoncxx {
18+
inline namespace v_noabi {
19+
namespace builder {
20+
namespace basic {
21+
22+
class array;
23+
24+
} // namespace basic
25+
} // namespace builder
26+
} // namespace v_noabi
27+
} // namespace bsoncxx

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/array.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/builder/basic/array-fwd.hpp>
18+
1719
#include <bsoncxx/array/value.hpp>
1820
#include <bsoncxx/array/view.hpp>
1921
#include <bsoncxx/builder/basic/impl.hpp>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023 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+
namespace bsoncxx {
18+
inline namespace v_noabi {
19+
namespace builder {
20+
namespace basic {
21+
22+
class document;
23+
24+
} // namespace basic
25+
} // namespace builder
26+
} // namespace v_noabi
27+
} // namespace bsoncxx

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/basic/document.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/builder/basic/array-fwd.hpp>
18+
#include <bsoncxx/builder/basic/document-fwd.hpp>
19+
1720
#include <bsoncxx/builder/basic/impl.hpp>
1821
#include <bsoncxx/builder/basic/kvp.hpp>
1922
#include <bsoncxx/builder/basic/sub_document.hpp>
@@ -28,8 +31,6 @@ inline namespace v_noabi {
2831
namespace builder {
2932
namespace basic {
3033

31-
class array;
32-
3334
///
3435
/// A traditional builder-style interface for constructing
3536
/// a BSON document.

0 commit comments

Comments
 (0)