-
Notifications
You must be signed in to change notification settings - Fork 548
CXX-3233 add bsoncxx v1 implementations and tests #1430
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 all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9fc87c6
v1: impls
eramongodb b034251
v1: tests
eramongodb e51551b
Merge remote-tracking branch 'upstream/master' into cxx-abi-v1-impls
eramongodb f258f76
Add some basic find() and subscript assertions
eramongodb 25354e4
Fix doc comments for BSON array data
eramongodb b2a4393
Do not violate precondition in our own test cases
eramongodb 1bc5302
Assert resulting document length in invalid_length assertions
eramongodb 877cd50
Remove unused values array
eramongodb 9e3d254
Fix view vs. value in btype_vs_value static assertions
eramongodb 2cfc2d7
Move T -> T::impl conversion functions into T::impl
eramongodb 8de4ee1
ClangFormat
eramongodb a3fd459
Merge remote-tracking branch 'upstream/master' into cxx-abi-v1-impls
eramongodb 1a94bf7
Merge remote-tracking branch 'upstream/master' into HEAD
eramongodb 2b76d2c
Distinguish "missing" vs. "invalid" after calling bson_iter_*
eramongodb 4c6b735
Use std::array instead of raw arrays
eramongodb 81fa5c0
BSON binary subtype values 128-255 are "user defined"
eramongodb 22c67c2
Minor mem-list-init improvement
eramongodb 4258c04
Make WSAGuard Windows-only and static local
eramongodb 116890e
Use bsoncxx::make_unique_for_overwrite
eramongodb 3de63ff
Fix and cleanup include directives
eramongodb e5c7fa9
Use common format for unknown error codes
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,117 @@ | |
|
|
||
| // | ||
|
|
||
| #include <bsoncxx/v1/exception.hpp> | ||
|
|
||
| #include <climits> | ||
| #include <cstddef> | ||
| #include <string> | ||
| #include <system_error> | ||
|
|
||
| #include <bsoncxx/private/bson.hh> | ||
| #include <bsoncxx/private/immortal.hh> | ||
| #include <bsoncxx/private/type_traits.hh> | ||
|
|
||
| namespace bsoncxx { | ||
| namespace v1 { | ||
|
|
||
| using code = v1::decimal128::errc; | ||
|
|
||
| static_assert(is_regular<decimal128>::value, "bsoncxx::v1::decimal128 must be regular"); | ||
| static_assert(is_semitrivial<decimal128>::value, "bsoncxx::v1::decimal128 must be semitrivial"); | ||
|
|
||
| decimal128::decimal128(v1::stdx::string_view sv) { | ||
| if (sv.empty()) { | ||
| throw v1::exception{code::empty_string}; | ||
| } | ||
|
|
||
| if (sv.size() > std::size_t{INT_MAX}) { | ||
| throw v1::exception{code::invalid_string_length}; | ||
| } | ||
|
Comment on lines
+39
to
+45
Contributor
Author
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. These checks are not present in v_noabi. |
||
|
|
||
| bson_decimal128_t d128; | ||
|
|
||
| if (!bson_decimal128_from_string_w_len(sv.data(), static_cast<int>(sv.size()), &d128)) { | ||
| throw v1::exception{code::invalid_string_data}; | ||
| } | ||
|
|
||
| _high = d128.high; | ||
| _low = d128.low; | ||
| } | ||
|
|
||
| std::string decimal128::to_string() const { | ||
| bson_decimal128_t d128; | ||
| d128.high = _high; | ||
| d128.low = _low; | ||
| char str[BSON_DECIMAL128_STRING]; | ||
| bson_decimal128_to_string(&d128, str); | ||
| return {str}; | ||
| } | ||
|
|
||
| std::error_category const& decimal128::error_category() { | ||
| class type final : public std::error_category { | ||
| char const* name() const noexcept override { | ||
| return "bsoncxx::v1::decimal128"; | ||
| } | ||
|
|
||
| std::string message(int v) const noexcept override { | ||
| switch (static_cast<code>(v)) { | ||
| case code::zero: | ||
| return "zero"; | ||
| case code::empty_string: | ||
| return "string must not be empty"; | ||
| case code::invalid_string_length: | ||
| return "length of string is too long (exceeds INT_MAX)"; | ||
| case code::invalid_string_data: | ||
| return "string is not a valid Decimal128 representation"; | ||
| default: | ||
| return std::string(this->name()) + ':' + std::to_string(v); | ||
| } | ||
| } | ||
|
|
||
| bool equivalent(int v, std::error_condition const& ec) const noexcept override { | ||
| if (ec.category() == v1::source_error_category()) { | ||
| using condition = v1::source_errc; | ||
|
|
||
| auto const source = static_cast<condition>(ec.value()); | ||
|
|
||
| switch (static_cast<code>(v)) { | ||
| case code::empty_string: | ||
| case code::invalid_string_length: | ||
| case code::invalid_string_data: | ||
| return source == condition::bsoncxx; | ||
|
|
||
| case code::zero: | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (ec.category() == v1::type_error_category()) { | ||
| using condition = v1::type_errc; | ||
|
|
||
| auto const type = static_cast<condition>(ec.value()); | ||
|
|
||
| switch (static_cast<code>(v)) { | ||
| case code::empty_string: | ||
| case code::invalid_string_length: | ||
| case code::invalid_string_data: | ||
| return type == condition::invalid_argument; | ||
|
|
||
| case code::zero: | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| static bsoncxx::immortal<type> const instance; | ||
|
|
||
| return instance.value(); | ||
| } | ||
|
|
||
| } // namespace v1 | ||
| } // namespace bsoncxx | ||
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
Oops, something went wrong.
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.
This check is not present in v_noabi). This is a consequence of the new, well-defined "invalid" state of an array view.