-
Notifications
You must be signed in to change notification settings - Fork 543
CXX-3082 Add examples for bsoncxx::v_noabi::builder::concatenate #1224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc21039
Add examples for bsoncxx::v_noabi::builder::concatenate
eramongodb 5346bdd
Update concatenate overload docs to avoid stream builder specificity
eramongodb ac569df
Use make_array instead of from_json
eramongodb d215590
Fix argument to bsoncxx::array::element
eramongodb d96ae17
Avoid mixing concatenate types with builders
eramongodb c761fdb
Additional comments to be updated
eramongodb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
examples/api/bsoncxx/examples/bson_documents/create_array/builder_concatenate.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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. | ||
|
||
#include <iostream> | ||
|
||
#include <bsoncxx/array/view.hpp> | ||
#include <bsoncxx/builder/basic/array.hpp> | ||
#include <bsoncxx/builder/concatenate.hpp> | ||
|
||
#include <examples/api/runner.hh> | ||
#include <examples/macros.hh> | ||
|
||
namespace { | ||
|
||
// [Example] | ||
// a: [1] | ||
// b: [2] | ||
void example(bsoncxx::array::view a, bsoncxx::array::view b) { | ||
bsoncxx::builder::basic::array builder; | ||
|
||
builder.append(bsoncxx::builder::concatenate(a)); | ||
builder.append(bsoncxx::builder::concatenate(b)); | ||
|
||
ASSERT(builder.view() == bsoncxx::builder::basic::make_array(1, 2)); | ||
} | ||
// [Example] | ||
|
||
} // namespace | ||
|
||
RUNNER_REGISTER_COMPONENT() { | ||
example(bsoncxx::builder::basic::make_array(1), bsoncxx::builder::basic::make_array(2)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
examples/api/bsoncxx/examples/bson_documents/create_doc/builder_concatenate.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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. | ||
|
||
#include <bsoncxx/builder/basic/document.hpp> | ||
#include <bsoncxx/builder/concatenate.hpp> | ||
#include <bsoncxx/document/view.hpp> | ||
#include <bsoncxx/json.hpp> | ||
|
||
#include <examples/api/runner.hh> | ||
#include <examples/macros.hh> | ||
|
||
namespace { | ||
|
||
// [Example] | ||
// a: {"a": 1} | ||
// b: {"b": 2} | ||
void example(bsoncxx::document::view a, bsoncxx::document::view b) { | ||
bsoncxx::builder::basic::document builder; | ||
|
||
builder.append(bsoncxx::builder::concatenate(a)); | ||
builder.append(bsoncxx::builder::concatenate(b)); | ||
|
||
ASSERT(builder.view() == bsoncxx::from_json(R"({"a": 1, "b": 2})")); | ||
} | ||
// [Example] | ||
|
||
} // namespace | ||
|
||
RUNNER_REGISTER_COMPONENT() { | ||
example(bsoncxx::from_json(R"({"a": 1})"), bsoncxx::from_json(R"({"b": 2})")); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,8 +26,10 @@ namespace v_noabi { | |||||||||
namespace builder { | ||||||||||
|
||||||||||
/// | ||||||||||
/// Container to concatenate a document. Use it by constructing an instance with the | ||||||||||
/// document to be concatenated, and pass it into a document stream builder. | ||||||||||
/// Container to concatenate a document. | ||||||||||
/// | ||||||||||
/// Use this with a document builder to merge an existing document's fields with that of the | ||||||||||
/// document being built. | ||||||||||
/// | ||||||||||
struct concatenate_doc { | ||||||||||
document::view_or_value doc; | ||||||||||
|
@@ -54,8 +56,10 @@ struct concatenate_doc { | |||||||||
}; | ||||||||||
|
||||||||||
/// | ||||||||||
/// Container to concatenate an array. Use this with the array stream builder in order | ||||||||||
/// to pass an array into a new builder and append its values to the stream. | ||||||||||
/// Container to concatenate an array. | ||||||||||
/// | ||||||||||
/// Use this with an array builder to merge an existing array's fields with that of the array being | ||||||||||
/// built. | ||||||||||
/// | ||||||||||
struct concatenate_array { | ||||||||||
array::view_or_value array; | ||||||||||
|
@@ -84,8 +88,8 @@ struct concatenate_array { | |||||||||
/// | ||||||||||
/// Helper method to concatenate a document. | ||||||||||
/// | ||||||||||
/// Use this with the document stream builder to merge an existing document's fields with a new | ||||||||||
/// document's. | ||||||||||
/// Use this with a document or array builder to merge an existing document's fields with that of | ||||||||||
/// the document or array being built. | ||||||||||
/// | ||||||||||
/// @param doc The document to concatenate. | ||||||||||
/// | ||||||||||
|
@@ -101,15 +105,15 @@ inline concatenate_doc concatenate(document::view_or_value doc) { | |||||||||
/// | ||||||||||
/// Helper method to concatenate an array. | ||||||||||
/// | ||||||||||
/// Use this with the document stream builder to merge an existing array's fields with a new | ||||||||||
/// document's. | ||||||||||
/// Use this with a document or array builder to merge an existing array's fields with that of the | ||||||||||
/// document or array being built. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
/// | ||||||||||
/// @param array The array to concatenate. | ||||||||||
/// | ||||||||||
/// @return concatenate_doc A concatenating struct. | ||||||||||
/// | ||||||||||
/// @see | ||||||||||
/// - @ref bsoncxx::v_noabi::builder::concatenate_doc | ||||||||||
/// - @ref bsoncxx::v_noabi::builder::concatenate_array | ||||||||||
/// | ||||||||||
inline concatenate_array concatenate(array::view_or_value array) { | ||||||||||
return {std::move(array)}; | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.