From 6e4e17c803111a039a96e65f3ea68756829f3802 Mon Sep 17 00:00:00 2001 From: David Golden Date: Wed, 21 Dec 2016 11:37:36 -0500 Subject: [PATCH] CXX-1007 Add additional directives to .clang-format This makes some additions/changes based on the MongoDB server's .clang-formatting rules. To have tighter code for empty subs: - AllowShortFunctionsOnASingleLine: Empty To keep control code structure visually distinct: - AllowShortIfStatementsOnASingleLine: false - AllowShortLoopsOnASingleLine: false To make long parameter/argument list easier to read: - BinPackArguments: false - BinPackParameters: false To have pointer and reference symbols consistent everywhere: - DerivePointerAlignment: false --- .clang-format | 7 +- examples/bsoncxx/builder_basic.cpp | 23 +- .../bsoncxx/builder_stream_customization.cpp | 6 +- examples/bsoncxx/view_and_value.cpp | 22 +- examples/mongocxx/connect.cpp | 9 +- examples/mongocxx/instance_management.cpp | 9 +- examples/mongocxx/query_projection.cpp | 4 +- src/bsoncxx/array/element.cpp | 6 +- src/bsoncxx/array/value.cpp | 9 +- src/bsoncxx/array/view.cpp | 12 +- src/bsoncxx/array/view.hpp | 8 +- src/bsoncxx/builder/basic/array.hpp | 3 +- src/bsoncxx/builder/basic/document.hpp | 3 +- src/bsoncxx/builder/basic/sub_array.hpp | 6 +- src/bsoncxx/builder/basic/sub_document.hpp | 6 +- src/bsoncxx/builder/core.cpp | 36 +-- src/bsoncxx/builder/stream/array.hpp | 3 +- src/bsoncxx/builder/stream/array_context.hpp | 3 +- src/bsoncxx/builder/stream/closed_context.hpp | 3 +- src/bsoncxx/builder/stream/document.hpp | 3 +- src/bsoncxx/builder/stream/helpers.hpp | 15 +- src/bsoncxx/builder/stream/key_context.hpp | 3 +- src/bsoncxx/builder/stream/single_context.hpp | 3 +- src/bsoncxx/builder/stream/value_context.hpp | 3 +- src/bsoncxx/decimal128.hpp | 3 +- src/bsoncxx/document/element.cpp | 12 +- src/bsoncxx/document/value.cpp | 9 +- src/bsoncxx/document/view.cpp | 12 +- src/bsoncxx/document/view.hpp | 8 +- src/bsoncxx/json.cpp | 6 +- src/bsoncxx/oid.cpp | 3 +- src/bsoncxx/private/b64_ntop.hh | 7 +- src/bsoncxx/private/itoa.cpp | 6 +- src/bsoncxx/private/stack.hh | 20 +- src/bsoncxx/string/view_or_value.hpp | 6 +- src/bsoncxx/test/bson_builder.cpp | 7 +- src/bsoncxx/types.hpp | 31 +-- src/bsoncxx/util/functor.hpp | 2 +- src/bsoncxx/validate.cpp | 12 +- src/bsoncxx/validate.hpp | 4 +- src/bsoncxx/view_or_value.hpp | 9 +- src/mongocxx/client.cpp | 6 +- src/mongocxx/collection.cpp | 62 +++-- src/mongocxx/collection.hpp | 24 +- src/mongocxx/cursor.cpp | 3 +- src/mongocxx/database.cpp | 12 +- .../exception/operation_exception.cpp | 3 +- .../exception/operation_exception.hpp | 3 +- .../exception/private/mongoc_error.hh | 6 +- src/mongocxx/hint.cpp | 6 +- src/mongocxx/insert_many_builder.cpp | 3 +- src/mongocxx/instance.cpp | 36 +-- src/mongocxx/logger.hpp | 3 +- src/mongocxx/model/delete_many.cpp | 3 +- src/mongocxx/model/delete_one.cpp | 3 +- src/mongocxx/model/insert_one.cpp | 4 +- src/mongocxx/model/replace_one.cpp | 3 +- src/mongocxx/model/update_many.cpp | 3 +- src/mongocxx/model/update_one.cpp | 3 +- src/mongocxx/options/bulk_write.cpp | 3 +- src/mongocxx/pipeline.cpp | 3 +- src/mongocxx/pool.cpp | 3 +- src/mongocxx/private/bulk_write.hh | 3 +- src/mongocxx/private/client.hh | 3 +- src/mongocxx/private/collection.hh | 9 +- src/mongocxx/private/cursor.hh | 3 +- src/mongocxx/private/database.hh | 6 +- src/mongocxx/private/libbson.cpp | 3 +- src/mongocxx/private/pool.hh | 3 +- src/mongocxx/private/read_concern.hh | 3 +- src/mongocxx/private/read_preference.hh | 3 +- src/mongocxx/private/uri.hh | 3 +- src/mongocxx/private/write_concern.hh | 3 +- src/mongocxx/read_concern.cpp | 9 +- src/mongocxx/read_preference.cpp | 6 +- src/mongocxx/result/bulk_write.cpp | 4 +- src/mongocxx/result/delete.cpp | 3 +- src/mongocxx/result/insert_one.cpp | 3 +- src/mongocxx/result/replace_one.cpp | 3 +- src/mongocxx/result/update.cpp | 3 +- src/mongocxx/test/bulk_write.cpp | 20 +- src/mongocxx/test/collection.cpp | 12 +- src/mongocxx/test/collection_mocked.cpp | 222 ++++++++++-------- src/mongocxx/test/database.cpp | 17 +- src/mongocxx/test/instance.cpp | 6 +- src/mongocxx/test/options/index.cpp | 4 +- src/mongocxx/test_util/mock.hh | 6 +- src/mongocxx/write_concern.cpp | 9 +- 88 files changed, 470 insertions(+), 456 deletions(-) diff --git a/.clang-format b/.clang-format index b1746b62d7..5b30f57768 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,12 @@ BasedOnStyle: Google -AllowShortFunctionsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BinPackArguments: false +BinPackParameters: false ColumnLimit: 100 Cpp11BracedListStyle: true +DerivePointerAlignment: false IndentWidth: 4 MaxEmptyLinesToKeep: 1 NamespaceIndentation: None diff --git a/examples/bsoncxx/builder_basic.cpp b/examples/bsoncxx/builder_basic.cpp index 74dd08e60b..7048a95b22 100644 --- a/examples/bsoncxx/builder_basic.cpp +++ b/examples/bsoncxx/builder_basic.cpp @@ -40,7 +40,8 @@ int main(int, char**) { doc.append(kvp("garply", types::b_double{3.14159})); // We can also pass a variable number of keys to append. - doc.append(kvp("a key", "a value"), kvp("another key", "another value"), + doc.append(kvp("a key", "a value"), + kvp("another key", "another value"), kvp("moar keys", "moar values")); // Appending to arrays is simple, just append one or more bson values. @@ -62,13 +63,19 @@ int main(int, char**) { subdoc.append(kvp("subdoc key", "subdoc value"), kvp("another subdoc key", types::b_int64{1212})); }), - kvp("subarray key", [](sub_array subarr) { - // subarrays work similarly - subarr.append(1, types::b_bool{false}, "hello", 5, [](sub_document subdoc) { - // nesting works too! - subdoc.append(kvp("such", "nesting"), kvp("much", "recurse")); - }); - })); + kvp("subarray key", + [](sub_array subarr) { + // subarrays work similarly + subarr.append(1, + types::b_bool{false}, + "hello", + 5, + [](sub_document subdoc) { + // nesting works too! + subdoc.append(kvp("such", "nesting"), + kvp("much", "recurse")); + }); + })); // We can get a view of the resulting bson by calling view() auto v = doc.view(); diff --git a/examples/bsoncxx/builder_stream_customization.cpp b/examples/bsoncxx/builder_stream_customization.cpp index ab0a9ec2fa..d094907fd3 100644 --- a/examples/bsoncxx/builder_stream_customization.cpp +++ b/examples/bsoncxx/builder_stream_customization.cpp @@ -25,8 +25,7 @@ using namespace bsoncxx; template class range_array_appender { public: - range_array_appender(begin_t begin, end_t end) : _begin(begin), _end(end) { - } + range_array_appender(begin_t begin, end_t end) : _begin(begin), _end(end) {} void operator()(bsoncxx::builder::stream::array_context<> ac) const { for (auto iter = _begin; iter != _end; ++iter) { @@ -49,8 +48,7 @@ range_array_appender make_range_array_appender(begin_t&& begin, template class range_kvp_appender { public: - range_kvp_appender(begin_t begin, end_t end) : _begin(begin), _end(end) { - } + range_kvp_appender(begin_t begin, end_t end) : _begin(begin), _end(end) {} void operator()(bsoncxx::builder::stream::key_context<> ac) const { for (auto iter = _begin; iter != _end; ++iter) { diff --git a/examples/bsoncxx/view_and_value.cpp b/examples/bsoncxx/view_and_value.cpp index 0c43fc94ee..bc356520b3 100644 --- a/examples/bsoncxx/view_and_value.cpp +++ b/examples/bsoncxx/view_and_value.cpp @@ -39,10 +39,13 @@ int main(int, char**) { using builder::basic::sub_array; auto doc = builder::basic::document{}; - doc.append(kvp("team", "platforms"), kvp("id", types::b_oid{oid()}), - kvp("members", [](sub_array sa) { - sa.append("tyler", "jason", "drew", "sam", "ernie", "john", "mark", "crystal"); - })); + doc.append(kvp("team", "platforms"), + kvp("id", types::b_oid{oid()}), + kvp("members", + [](sub_array sa) { + sa.append( + "tyler", "jason", "drew", "sam", "ernie", "john", "mark", "crystal"); + })); // document::value is an owning bson document conceptually similar to string. document::value value{doc.extract()}; @@ -112,10 +115,13 @@ int main(int, char**) { // i.e. if we want a vector of all the keys in a document, we can use std::transform std::vector doc_keys; - std::transform(begin(view), end(view), std::back_inserter(doc_keys), [](document::element ele) { - // note that key() returns a string_view - return ele.key().to_string(); - }); + std::transform(begin(view), + end(view), + std::back_inserter(doc_keys), + [](document::element ele) { + // note that key() returns a string_view + return ele.key().to_string(); + }); std::cout << "document keys are: " << std::endl; for (auto key : doc_keys) { diff --git a/examples/mongocxx/connect.cpp b/examples/mongocxx/connect.cpp index 3ae2d7287b..e3c0da4a5f 100644 --- a/examples/mongocxx/connect.cpp +++ b/examples/mongocxx/connect.cpp @@ -30,12 +30,13 @@ namespace { class logger final : public mongocxx::logger { public: - explicit logger(std::ostream* stream) : _stream(stream) { - } + explicit logger(std::ostream* stream) : _stream(stream) {} - void operator()(mongocxx::log_level level, mongocxx::stdx::string_view domain, + void operator()(mongocxx::log_level level, + mongocxx::stdx::string_view domain, mongocxx::stdx::string_view message) noexcept override { - if (level >= mongocxx::log_level::k_trace) return; + if (level >= mongocxx::log_level::k_trace) + return; *_stream << '[' << mongocxx::to_string(level) << '@' << domain << "] " << message << '\n'; } diff --git a/examples/mongocxx/instance_management.cpp b/examples/mongocxx/instance_management.cpp index 010b96434c..688839f3a8 100644 --- a/examples/mongocxx/instance_management.cpp +++ b/examples/mongocxx/instance_management.cpp @@ -73,9 +73,9 @@ class mongo_access { void configure(mongocxx::uri uri) { class noop_logger : public mongocxx::logger { public: - virtual void operator()(mongocxx::log_level, mongocxx::stdx::string_view, - mongocxx::stdx::string_view) noexcept { - } + virtual void operator()(mongocxx::log_level, + mongocxx::stdx::string_view, + mongocxx::stdx::string_view) noexcept {} }; auto instance = @@ -87,7 +87,8 @@ void configure(mongocxx::uri uri) { bool do_work() { auto connection = mongo_access::instance().get_connection(); - if (!connection) return false; + if (!connection) + return false; return true; } diff --git a/examples/mongocxx/query_projection.cpp b/examples/mongocxx/query_projection.cpp index 9384bd0fd4..0c2e36b640 100644 --- a/examples/mongocxx/query_projection.cpp +++ b/examples/mongocxx/query_projection.cpp @@ -13,7 +13,7 @@ using bsoncxx::builder::stream::open_document; using bsoncxx::builder::stream::close_document; using bsoncxx::builder::stream::finalize; -int main(int, char **) { +int main(int, char**) { mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{}}; @@ -36,7 +36,7 @@ int main(int, char **) { // Execute find with options auto cursor = coll.find(filter.view(), opts); - for (auto &&doc : cursor) { + for (auto&& doc : cursor) { std::cout << bsoncxx::to_json(doc) << std::endl; } diff --git a/src/bsoncxx/array/element.cpp b/src/bsoncxx/array/element.cpp index 8ed6eb9aec..fd832c3a2f 100644 --- a/src/bsoncxx/array/element.cpp +++ b/src/bsoncxx/array/element.cpp @@ -24,12 +24,10 @@ namespace bsoncxx { BSONCXX_INLINE_NAMESPACE_BEGIN namespace array { -element::element() : document::element() { -} +element::element() : document::element() {} element::element(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset) - : document::element(raw, length, offset) { -} + : document::element(raw, length, offset) {} } // namespace document BSONCXX_INLINE_NAMESPACE_END diff --git a/src/bsoncxx/array/value.cpp b/src/bsoncxx/array/value.cpp index 58117ff777..922e245c6f 100644 --- a/src/bsoncxx/array/value.cpp +++ b/src/bsoncxx/array/value.cpp @@ -24,11 +24,9 @@ BSONCXX_INLINE_NAMESPACE_BEGIN namespace array { value::value(std::uint8_t* data, std::size_t length, deleter_type dtor) - : _data(data, dtor), _length(length) { -} + : _data(data, dtor), _length(length) {} -value::value(unique_ptr_type ptr, std::size_t length) : _data(std::move(ptr)), _length(length) { -} +value::value(unique_ptr_type ptr, std::size_t length) : _data(std::move(ptr)), _length(length) {} namespace { @@ -44,8 +42,7 @@ value::value(array::view view) std::copy(view.data(), view.data() + view.length(), _data.get()); } -value::value(const value& rhs) : value(rhs.view()) { -} +value::value(const value& rhs) : value(rhs.view()) {} value& value::operator=(const value& rhs) { *this = value{rhs.view()}; diff --git a/src/bsoncxx/array/view.cpp b/src/bsoncxx/array/view.cpp index a16a7053b8..83b4de1686 100644 --- a/src/bsoncxx/array/view.cpp +++ b/src/bsoncxx/array/view.cpp @@ -39,11 +39,9 @@ bson_iter_t to_bson_iter_t(element e) { } } // namespace -view::const_iterator::const_iterator() { -} +view::const_iterator::const_iterator() {} -view::const_iterator::const_iterator(const element& element) : _element(element) { -} +view::const_iterator::const_iterator(const element& element) : _element(element) {} view::const_iterator::reference view::const_iterator::operator*() { return _element; @@ -141,11 +139,9 @@ element view::operator[](std::uint32_t i) const { return *(this->find(i)); } -view::view(const std::uint8_t* data, std::size_t length) : _view(data, length) { -} +view::view(const std::uint8_t* data, std::size_t length) : _view(data, length) {} -view::view() : _view() { -} +view::view() : _view() {} const std::uint8_t* view::data() const { return _view.data(); diff --git a/src/bsoncxx/array/view.hpp b/src/bsoncxx/array/view.hpp index c396a55905..dd3ac2bc96 100644 --- a/src/bsoncxx/array/view.hpp +++ b/src/bsoncxx/array/view.hpp @@ -146,9 +146,11 @@ class BSONCXX_API view { /// This iterator type provides a const forward iterator interface to array /// view elements. /// -class BSONCXX_API view::const_iterator - : public std::iterator { +class BSONCXX_API view::const_iterator : public std::iterator { public: const_iterator(); explicit const_iterator(const element& element); diff --git a/src/bsoncxx/builder/basic/array.hpp b/src/bsoncxx/builder/basic/array.hpp index e9182ec6e4..c031fca287 100644 --- a/src/bsoncxx/builder/basic/array.hpp +++ b/src/bsoncxx/builder/basic/array.hpp @@ -37,8 +37,7 @@ class array : public sub_array { /// /// Default constructor /// - BSONCXX_INLINE array() : sub_array(&_core), _core(true) { - } + BSONCXX_INLINE array() : sub_array(&_core), _core(true) {} /// /// @return A view of the BSON array. diff --git a/src/bsoncxx/builder/basic/document.hpp b/src/bsoncxx/builder/basic/document.hpp index 8dcc24cef2..36f5803b5e 100644 --- a/src/bsoncxx/builder/basic/document.hpp +++ b/src/bsoncxx/builder/basic/document.hpp @@ -36,8 +36,7 @@ class array; /// class document : public sub_document { public: - BSONCXX_INLINE document() : sub_document(&_core), _core(false) { - } + BSONCXX_INLINE document() : sub_document(&_core), _core(false) {} /// /// @return A view of the BSON document. diff --git a/src/bsoncxx/builder/basic/sub_array.hpp b/src/bsoncxx/builder/basic/sub_array.hpp index 79f153f288..ef8f3d0388 100644 --- a/src/bsoncxx/builder/basic/sub_array.hpp +++ b/src/bsoncxx/builder/basic/sub_array.hpp @@ -41,8 +41,7 @@ class sub_array { /// /// Default constructor /// - BSONCXX_INLINE sub_array(core* core) : _core(core) { - } + BSONCXX_INLINE sub_array(core* core) : _core(core) {} /// /// Appends multiple BSON values. @@ -57,8 +56,7 @@ class sub_array { /// Inductive base-case for the variadic append(...) /// BSONCXX_INLINE - void append() { - } + void append() {} private: // diff --git a/src/bsoncxx/builder/basic/sub_document.hpp b/src/bsoncxx/builder/basic/sub_document.hpp index f9314b38db..93f538ea66 100644 --- a/src/bsoncxx/builder/basic/sub_document.hpp +++ b/src/bsoncxx/builder/basic/sub_document.hpp @@ -37,8 +37,7 @@ void value_append(core* core, T&& t); /// class sub_document { public: - BSONCXX_INLINE sub_document(core* core) : _core(core) { - } + BSONCXX_INLINE sub_document(core* core) : _core(core) {} /// /// Appends multiple basic::kvp key-value pairs. @@ -53,8 +52,7 @@ class sub_document { /// Inductive base-case for the variadic append(...) /// BSONCXX_INLINE - void append() { - } + void append() {} private: // diff --git a/src/bsoncxx/builder/core.cpp b/src/bsoncxx/builder/core.cpp index d8f32e2ed3..a6d5d5540c 100644 --- a/src/bsoncxx/builder/core.cpp +++ b/src/bsoncxx/builder/core.cpp @@ -214,8 +214,7 @@ class core::impl { bool _has_user_key; }; -core::core(bool is_array) : _impl(new impl(is_array)) { -} +core::core(bool is_array) : _impl(new impl(is_array)) {} core::core(core&&) noexcept = default; core& core::operator=(core&&) noexcept = default; core::~core() = default; @@ -243,8 +242,8 @@ void core::append(const types::b_double& value) { void core::append(const types::b_utf8& value) { stdx::string_view key = _impl->next_key(); - bson_append_utf8(_impl->back(), key.data(), key.length(), value.value.data(), - value.value.length()); + bson_append_utf8( + _impl->back(), key.data(), key.length(), value.value.data(), value.value.length()); } void core::append(const types::b_document& value) { @@ -266,8 +265,12 @@ void core::append(const types::b_array& value) { void core::append(const types::b_binary& value) { stdx::string_view key = _impl->next_key(); - bson_append_binary(_impl->back(), key.data(), key.length(), - static_cast(value.sub_type), value.bytes, value.size); + bson_append_binary(_impl->back(), + key.data(), + key.length(), + static_cast(value.sub_type), + value.bytes, + value.size); } void core::append(const types::b_undefined&) { @@ -305,7 +308,10 @@ void core::append(const types::b_null&) { void core::append(const types::b_regex& value) { stdx::string_view key = _impl->next_key(); - bson_append_regex(_impl->back(), key.data(), key.length(), value.regex.to_string().data(), + bson_append_regex(_impl->back(), + key.data(), + key.length(), + value.regex.to_string().data(), value.options.to_string().data()); } @@ -315,8 +321,8 @@ void core::append(const types::b_dbpointer& value) { bson_oid_t oid; std::memcpy(&oid.bytes, value.value.bytes(), sizeof(oid.bytes)); - bson_append_dbpointer(_impl->back(), key.data(), key.length(), - value.collection.to_string().data(), &oid); + bson_append_dbpointer( + _impl->back(), key.data(), key.length(), value.collection.to_string().data(), &oid); } void core::append(const types::b_code& value) { @@ -328,8 +334,8 @@ void core::append(const types::b_code& value) { void core::append(const types::b_symbol& value) { stdx::string_view key = _impl->next_key(); - bson_append_symbol(_impl->back(), key.data(), key.length(), value.symbol.data(), - value.symbol.length()); + bson_append_symbol( + _impl->back(), key.data(), key.length(), value.symbol.data(), value.symbol.length()); } void core::append(const types::b_codewscope& value) { @@ -338,8 +344,8 @@ void core::append(const types::b_codewscope& value) { bson_t bson; bson_init_static(&bson, value.scope.data(), value.scope.length()); - bson_append_code_with_scope(_impl->back(), key.data(), key.length(), - value.code.to_string().data(), &bson); + bson_append_code_with_scope( + _impl->back(), key.data(), key.length(), value.code.to_string().data(), &bson); } void core::append(const types::b_int32& value) { @@ -351,8 +357,8 @@ void core::append(const types::b_int32& value) { void core::append(const types::b_timestamp& value) { stdx::string_view key = _impl->next_key(); - bson_append_timestamp(_impl->back(), key.data(), key.length(), value.increment, - value.timestamp); + bson_append_timestamp( + _impl->back(), key.data(), key.length(), value.increment, value.timestamp); } void core::append(const types::b_int64& value) { diff --git a/src/bsoncxx/builder/stream/array.hpp b/src/bsoncxx/builder/stream/array.hpp index 31959b0031..24682114ea 100644 --- a/src/bsoncxx/builder/stream/array.hpp +++ b/src/bsoncxx/builder/stream/array.hpp @@ -38,8 +38,7 @@ class array : public array_context<> { /// /// Default constructor. /// - BSONCXX_INLINE array() : array_context<>(&_core), _core(true) { - } + BSONCXX_INLINE array() : array_context<>(&_core), _core(true) {} /// /// @return A view of the BSON array. diff --git a/src/bsoncxx/builder/stream/array_context.hpp b/src/bsoncxx/builder/stream/array_context.hpp index a65fe289bc..2af631ee14 100644 --- a/src/bsoncxx/builder/stream/array_context.hpp +++ b/src/bsoncxx/builder/stream/array_context.hpp @@ -57,8 +57,7 @@ class array_context { /// @param core /// The core builder to orchestrate /// - BSONCXX_INLINE array_context(core* core) : _core(core) { - } + BSONCXX_INLINE array_context(core* core) : _core(core) {} /// /// << operator for accepting a real value and appending it to the core diff --git a/src/bsoncxx/builder/stream/closed_context.hpp b/src/bsoncxx/builder/stream/closed_context.hpp index cb1b2efffd..b0fe9cc80e 100644 --- a/src/bsoncxx/builder/stream/closed_context.hpp +++ b/src/bsoncxx/builder/stream/closed_context.hpp @@ -32,8 +32,7 @@ namespace stream { /// the stream api. /// struct closed_context { - closed_context(core*) { - } + closed_context(core*) {} }; } // namespace stream diff --git a/src/bsoncxx/builder/stream/document.hpp b/src/bsoncxx/builder/stream/document.hpp index 2b16b53d28..5d7375da9e 100644 --- a/src/bsoncxx/builder/stream/document.hpp +++ b/src/bsoncxx/builder/stream/document.hpp @@ -36,8 +36,7 @@ class document : public key_context<> { /// /// Default constructor. /// - BSONCXX_INLINE document() : key_context<>(&_core), _core(false) { - } + BSONCXX_INLINE document() : key_context<>(&_core), _core(false) {} /// /// @return A view of the BSON document. diff --git a/src/bsoncxx/builder/stream/helpers.hpp b/src/bsoncxx/builder/stream/helpers.hpp index 0d2cdd5d54..84436dfa50 100644 --- a/src/bsoncxx/builder/stream/helpers.hpp +++ b/src/bsoncxx/builder/stream/helpers.hpp @@ -27,8 +27,7 @@ namespace stream { using bsoncxx::builder::concatenate; struct BSONCXX_API open_document_type { - constexpr open_document_type() { - } + constexpr open_document_type() {} }; /// @@ -37,8 +36,7 @@ struct BSONCXX_API open_document_type { constexpr open_document_type open_document; struct BSONCXX_API close_document_type { - constexpr close_document_type() { - } + constexpr close_document_type() {} }; /// @@ -47,8 +45,7 @@ struct BSONCXX_API close_document_type { constexpr close_document_type close_document; struct BSONCXX_API open_array_type { - constexpr open_array_type() { - } + constexpr open_array_type() {} }; /// @@ -57,8 +54,7 @@ struct BSONCXX_API open_array_type { constexpr open_array_type open_array; struct BSONCXX_API close_array_type { - constexpr close_array_type() { - } + constexpr close_array_type() {} }; /// @@ -67,8 +63,7 @@ struct BSONCXX_API close_array_type { constexpr close_array_type close_array; struct BSONCXX_API finalize_type { - constexpr finalize_type() { - } + constexpr finalize_type() {} }; /// diff --git a/src/bsoncxx/builder/stream/key_context.hpp b/src/bsoncxx/builder/stream/key_context.hpp index 85f8fb30a1..e54f3fbf55 100644 --- a/src/bsoncxx/builder/stream/key_context.hpp +++ b/src/bsoncxx/builder/stream/key_context.hpp @@ -54,8 +54,7 @@ class key_context { /// @param core /// The core builder to orchestrate /// - key_context(core* core) : _core(core) { - } + key_context(core* core) : _core(core) {} /// /// << operator for accepting a literal key and appending it to the core diff --git a/src/bsoncxx/builder/stream/single_context.hpp b/src/bsoncxx/builder/stream/single_context.hpp index 83837940da..2f27e431ba 100644 --- a/src/bsoncxx/builder/stream/single_context.hpp +++ b/src/bsoncxx/builder/stream/single_context.hpp @@ -41,8 +41,7 @@ class single_context { /// @param core /// The core builder to orchestrate /// - BSONCXX_INLINE single_context(core* core) : _core(core) { - } + BSONCXX_INLINE single_context(core* core) : _core(core) {} /// /// << operator for opening a new subdocument in the core builder. diff --git a/src/bsoncxx/builder/stream/value_context.hpp b/src/bsoncxx/builder/stream/value_context.hpp index 8f12e32e3f..dcbdef81aa 100644 --- a/src/bsoncxx/builder/stream/value_context.hpp +++ b/src/bsoncxx/builder/stream/value_context.hpp @@ -53,8 +53,7 @@ class value_context { /// @param core /// The core builder to orchestrate /// - BSONCXX_INLINE value_context(core* core) : _core(core) { - } + BSONCXX_INLINE value_context(core* core) : _core(core) {} /// /// << operator for accepting a real value and appending it to the core diff --git a/src/bsoncxx/decimal128.hpp b/src/bsoncxx/decimal128.hpp index f7c82d6326..14dacdf4a7 100644 --- a/src/bsoncxx/decimal128.hpp +++ b/src/bsoncxx/decimal128.hpp @@ -42,8 +42,7 @@ class BSONCXX_API decimal128 { /// @param low /// The low 64-bits. /// - decimal128(uint64_t high, uint64_t low) noexcept : _high(high), _low(low) { - } + decimal128(uint64_t high, uint64_t low) noexcept : _high(high), _low(low) {} /// /// Constructs a BSON Decimal128 from a string. diff --git a/src/bsoncxx/document/element.cpp b/src/bsoncxx/document/element.cpp index 452d9cfb9d..db43f37090 100644 --- a/src/bsoncxx/document/element.cpp +++ b/src/bsoncxx/document/element.cpp @@ -45,12 +45,10 @@ namespace bsoncxx { BSONCXX_INLINE_NAMESPACE_BEGIN namespace document { -element::element() : _raw(nullptr), _length(0), _offset(0) { -} +element::element() : _raw(nullptr), _length(0), _offset(0) {} element::element(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset) - : _raw(raw), _length(length), _offset(offset) { -} + : _raw(raw), _length(length), _offset(offset) {} const std::uint8_t* element::raw() const { return _raw; @@ -286,13 +284,15 @@ types::value element::get_value() const { } element element::operator[](stdx::string_view key) const { - if (_raw == nullptr || type() != bsoncxx::type::k_document) return element(); + if (_raw == nullptr || type() != bsoncxx::type::k_document) + return element(); document::view doc = get_document(); return doc[key]; } array::element element::operator[](std::uint32_t i) const { - if (_raw == nullptr || type() != bsoncxx::type::k_array) return array::element(); + if (_raw == nullptr || type() != bsoncxx::type::k_array) + return array::element(); array::view arr = get_array(); return arr[i]; } diff --git a/src/bsoncxx/document/value.cpp b/src/bsoncxx/document/value.cpp index f2b0a4e12b..0ceef697bb 100644 --- a/src/bsoncxx/document/value.cpp +++ b/src/bsoncxx/document/value.cpp @@ -25,11 +25,9 @@ BSONCXX_INLINE_NAMESPACE_BEGIN namespace document { value::value(std::uint8_t* data, std::size_t length, deleter_type dtor) - : _data(data, dtor), _length(length) { -} + : _data(data, dtor), _length(length) {} -value::value(unique_ptr_type ptr, std::size_t length) : _data(std::move(ptr)), _length(length) { -} +value::value(unique_ptr_type ptr, std::size_t length) : _data(std::move(ptr)), _length(length) {} namespace { @@ -45,8 +43,7 @@ value::value(document::view view) std::copy(view.data(), view.data() + view.length(), _data.get()); } -value::value(const value& rhs) : value(rhs.view()) { -} +value::value(const value& rhs) : value(rhs.view()) {} value& value::operator=(const value& rhs) { *this = value{rhs.view()}; diff --git a/src/bsoncxx/document/view.cpp b/src/bsoncxx/document/view.cpp index 66965bcc2f..d626d10602 100644 --- a/src/bsoncxx/document/view.cpp +++ b/src/bsoncxx/document/view.cpp @@ -38,11 +38,9 @@ bson_iter_t to_bson_iter_t(element e) { } } // namespace -view::const_iterator::const_iterator() { -} +view::const_iterator::const_iterator() {} -view::const_iterator::const_iterator(const element& element) : _element(element) { -} +view::const_iterator::const_iterator(const element& element) : _element(element) {} view::const_iterator::reference view::const_iterator::operator*() { return _element; @@ -138,15 +136,13 @@ element view::operator[](stdx::string_view key) const { return *(this->find(key)); } -view::view(const std::uint8_t* data, std::size_t length) : _data(data), _length(length) { -} +view::view(const std::uint8_t* data, std::size_t length) : _data(data), _length(length) {} namespace { const uint8_t k_default_view[5] = {5, 0, 0, 0, 0}; } -view::view() : _data(k_default_view), _length(sizeof(k_default_view)) { -} +view::view() : _data(k_default_view), _length(sizeof(k_default_view)) {} const std::uint8_t* view::data() const { return _data; diff --git a/src/bsoncxx/document/view.hpp b/src/bsoncxx/document/view.hpp index 4dd796b359..aced460de0 100644 --- a/src/bsoncxx/document/view.hpp +++ b/src/bsoncxx/document/view.hpp @@ -150,9 +150,11 @@ class BSONCXX_API view { /// This iterator type provides a const forward iterator interface to document /// view elements. /// -class BSONCXX_API view::const_iterator - : public std::iterator { +class BSONCXX_API view::const_iterator : public std::iterator { public: const_iterator(); explicit const_iterator(const element& element); diff --git a/src/bsoncxx/json.cpp b/src/bsoncxx/json.cpp index ccb98b13bf..6fdd2dbe32 100644 --- a/src/bsoncxx/json.cpp +++ b/src/bsoncxx/json.cpp @@ -50,7 +50,8 @@ std::string to_json(document::view view) { size_t size; auto result = bson_as_json(&bson, &size); - if (!result) throw exception(error_code::k_failed_converting_bson_to_json); + if (!result) + throw exception(error_code::k_failed_converting_bson_to_json); const auto deleter = [](char* result) { bson_free(result); }; const std::unique_ptr cleanup(result, deleter); @@ -63,7 +64,8 @@ document::value from_json(stdx::string_view json) { bson_t* result = bson_new_from_json(reinterpret_cast(json.data()), json.size(), &error); - if (!result) throw exception(error_code::k_json_parse_failure, error.message); + if (!result) + throw exception(error_code::k_json_parse_failure, error.message); std::uint32_t length; std::uint8_t* buf = bson_destroy_with_steal(result, true, &length); diff --git a/src/bsoncxx/oid.cpp b/src/bsoncxx/oid.cpp index b8d2e6b3da..b902da36fc 100644 --- a/src/bsoncxx/oid.cpp +++ b/src/bsoncxx/oid.cpp @@ -34,8 +34,7 @@ oid::oid() { const oid::init_tag_t oid::init_tag{}; -oid::oid(init_tag_t) : oid::oid() { -} +oid::oid(init_tag_t) : oid::oid() {} oid::oid(const bsoncxx::stdx::string_view& str) { if (!bson_oid_is_valid(str.data(), str.size())) { diff --git a/src/bsoncxx/private/b64_ntop.hh b/src/bsoncxx/private/b64_ntop.hh index d01319d30b..aa39adce4f 100644 --- a/src/bsoncxx/private/b64_ntop.hh +++ b/src/bsoncxx/private/b64_ntop.hh @@ -52,7 +52,8 @@ BSONCXX_INLINE_NAMESPACE_BEGIN namespace b64 { #define BSONCXX_B64_ASSERT(Cond) \ - if (!(Cond)) std::abort() + if (!(Cond)) \ + std::abort() const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const char Pad64 = '='; @@ -119,7 +120,9 @@ const char Pad64 = '='; * characters followed by one "=" padding character. */ -BSONCXX_INLINE int ntop(std::uint8_t const *src, std::size_t srclength, char *target, +BSONCXX_INLINE int ntop(std::uint8_t const* src, + std::size_t srclength, + char* target, std::size_t targsize) { std::size_t datalength = 0; std::uint8_t input[3]; diff --git a/src/bsoncxx/private/itoa.cpp b/src/bsoncxx/private/itoa.cpp index fc3183ebfe..1a2af8fa1e 100644 --- a/src/bsoncxx/private/itoa.cpp +++ b/src/bsoncxx/private/itoa.cpp @@ -1054,11 +1054,9 @@ void itoa::init() { } } -itoa::itoa() : itoa(0) { -} +itoa::itoa() : itoa(0) {} -itoa::itoa(const itoa& rhs) : itoa(rhs._val) { -} +itoa::itoa(const itoa& rhs) : itoa(rhs._val) {} itoa& itoa::operator=(const itoa& rhs) { _val = rhs._val; diff --git a/src/bsoncxx/private/stack.hh b/src/bsoncxx/private/stack.hh index 049411dc14..2a0f3c0b91 100644 --- a/src/bsoncxx/private/stack.hh +++ b/src/bsoncxx/private/stack.hh @@ -26,8 +26,7 @@ BSONCXX_INLINE_NAMESPACE_BEGIN template class stack { public: - stack() : _bucket_index(0), _bucket_size(size), _is_empty(true) { - } + stack() : _bucket_index(0), _bucket_size(size), _is_empty(true) {} ~stack() { while (!empty()) { @@ -44,12 +43,12 @@ class stack { return _is_empty; } - T &back() { + T& back() { return *(_get_ptr()); } template - void emplace_back(Args &&... args) { + void emplace_back(Args&&... args) { if (_is_empty) { _is_empty = false; } else { @@ -74,17 +73,17 @@ class stack { private: typename std::aligned_storage::type _object_memory[size]; - std::list _buckets; + std::list _buckets; - typename std::list::iterator _bucket_iter; + typename std::list::iterator _bucket_iter; int _bucket_index; int _bucket_size; bool _is_empty; - T *_get_ptr() { + T* _get_ptr() { if (_bucket_size == size) { - return reinterpret_cast(_object_memory) + _bucket_index; + return reinterpret_cast(_object_memory) + _bucket_index; } else { return *(_bucket_iter) + _bucket_index; } @@ -97,8 +96,7 @@ class stack { if (_buckets.empty()) { // first pass at needing dynamic memory - _buckets.emplace_back( - reinterpret_cast(operator new(sizeof(T) * _bucket_size))); + _buckets.emplace_back(reinterpret_cast(operator new(sizeof(T) * _bucket_size))); _bucket_iter = _buckets.begin(); } else if (_bucket_size != size * 2) { @@ -107,7 +105,7 @@ class stack { if (++tmp_iter == _buckets.end()) { _buckets.emplace_back( - reinterpret_cast(operator new(sizeof(T) * _bucket_size))); + reinterpret_cast(operator new(sizeof(T) * _bucket_size))); } ++_bucket_iter; } diff --git a/src/bsoncxx/string/view_or_value.hpp b/src/bsoncxx/string/view_or_value.hpp index 118b3c5742..e5b5aa578e 100644 --- a/src/bsoncxx/string/view_or_value.hpp +++ b/src/bsoncxx/string/view_or_value.hpp @@ -53,8 +53,7 @@ class BSONCXX_API view_or_value : public bsoncxx::view_or_value(stdx::string_view(str)) { - } + : bsoncxx::view_or_value(stdx::string_view(str)) {} /// /// Allow construction with an l-value reference to a std::string. The resulting @@ -67,8 +66,7 @@ class BSONCXX_API view_or_value : public bsoncxx::view_or_value(stdx::string_view(str)) { - } + : bsoncxx::view_or_value(stdx::string_view(str)) {} /// /// Return a string_view_or_value that is guaranteed to hold a null-terminated diff --git a/src/bsoncxx/test/bson_builder.cpp b/src/bsoncxx/test/bson_builder.cpp index f7f26b3345..da07115576 100644 --- a/src/bsoncxx/test/bson_builder.cpp +++ b/src/bsoncxx/test/bson_builder.cpp @@ -813,9 +813,10 @@ TEST_CASE("basic document builder works", "[bsoncxx::builder::basic]") { { using namespace builder::basic; - basic.append(kvp("hello", "world"), kvp("foo", 35), kvp("bar", [](sub_document sd) { - sd.append(kvp("que", "qux")); - }), kvp("baz", [](sub_array sa) { sa.append(1, 2, 3); })); + basic.append(kvp("hello", "world"), + kvp("foo", 35), + kvp("bar", [](sub_document sd) { sd.append(kvp("que", "qux")); }), + kvp("baz", [](sub_array sa) { sa.append(1, 2, 3); })); } viewable_eq_viewable(stream, basic); diff --git a/src/bsoncxx/types.hpp b/src/bsoncxx/types.hpp index b8b17c1af2..0432d0b72b 100644 --- a/src/bsoncxx/types.hpp +++ b/src/bsoncxx/types.hpp @@ -120,8 +120,7 @@ struct BSONCXX_API b_utf8 { typename std::enable_if::type>::value, int>::type = 0> BSONCXX_INLINE explicit b_utf8(T&& t) - : value(std::forward(t)) { - } + : value(std::forward(t)) {} stdx::string_view value; @@ -295,8 +294,7 @@ struct BSONCXX_API b_date { /// Milliseconds since the system_clock epoch. /// BSONCXX_INLINE - explicit b_date(std::chrono::milliseconds value) : value(value) { - } + explicit b_date(std::chrono::milliseconds value) : value(value) {} /// /// Constructor for b_date @@ -306,8 +304,7 @@ struct BSONCXX_API b_date { /// BSONCXX_INLINE explicit b_date(const std::chrono::system_clock::time_point& tp) - : value(std::chrono::duration_cast(tp.time_since_epoch())) { - } + : value(std::chrono::duration_cast(tp.time_since_epoch())) {} std::chrono::milliseconds value; @@ -376,8 +373,7 @@ struct BSONCXX_API b_regex { /// template BSONCXX_INLINE explicit b_regex(T&& regex, U&& options) - : regex(std::forward(regex)), options(std::forward(options)) { - } + : regex(std::forward(regex)), options(std::forward(options)) {} stdx::string_view regex; stdx::string_view options; @@ -430,8 +426,7 @@ struct BSONCXX_API b_code { typename std::enable_if::type>::value, int>::type = 0> BSONCXX_INLINE explicit b_code(T&& t) - : code(std::forward(t)) { - } + : code(std::forward(t)) {} stdx::string_view code; @@ -471,8 +466,7 @@ struct BSONCXX_API b_symbol { typename std::enable_if::type>::value, int>::type = 0> BSONCXX_INLINE explicit b_symbol(T&& t) - : symbol(std::forward(t)) { - } + : symbol(std::forward(t)) {} stdx::string_view symbol; @@ -510,8 +504,7 @@ struct BSONCXX_API b_codewscope { /// template BSONCXX_INLINE explicit b_codewscope(T&& code, U&& scope) - : code(std::forward(code)), scope(std::forward(scope)) { - } + : code(std::forward(code)), scope(std::forward(scope)) {} stdx::string_view code; document::view scope; @@ -613,12 +606,12 @@ struct BSONCXX_API b_decimal128 { /// @param value /// The value to wrap. /// - template ::type>::value, int>::type = 0> + template < + typename T, + typename std::enable_if::type>::value, + int>::type = 0> BSONCXX_INLINE explicit b_decimal128(T&& t) - : value(std::forward(t)) { - } + : value(std::forward(t)) {} }; /// diff --git a/src/bsoncxx/util/functor.hpp b/src/bsoncxx/util/functor.hpp index 00cd38d35e..9506654301 100644 --- a/src/bsoncxx/util/functor.hpp +++ b/src/bsoncxx/util/functor.hpp @@ -81,7 +81,7 @@ struct is_class_method_with_signature { typename strip_cv_from_class_function< decltype(&T::operator())>::type>::value, yes>::type - sfinae(void *); + sfinae(void*); template static no sfinae(...); diff --git a/src/bsoncxx/validate.cpp b/src/bsoncxx/validate.cpp index 8a9512f953..03d68b05a7 100644 --- a/src/bsoncxx/validate.cpp +++ b/src/bsoncxx/validate.cpp @@ -30,8 +30,7 @@ struct validator::impl { bool _check_dot_keys{false}; }; -validator::validator() : _impl{stdx::make_unique()} { -} +validator::validator() : _impl{stdx::make_unique()} {} validator::~validator() = default; @@ -72,8 +71,10 @@ stdx::optional validate(const std::uint8_t* data, std::size_t le return validate(data, length, vtor); } -stdx::optional validate(const std::uint8_t* data, std::size_t length, - const validator& validator, std::size_t* invalid_offset) { +stdx::optional validate(const std::uint8_t* data, + std::size_t length, + const validator& validator, + std::size_t* invalid_offset) { ::bson_validate_flags_t flags = BSON_VALIDATE_NONE; const auto flip_if = [&flags](bool cond, ::bson_validate_flags_t flag) { @@ -94,7 +95,8 @@ stdx::optional validate(const std::uint8_t* data, std::size_t le ::bson_t bson; if (!::bson_init_static(&bson, data, length)) { // if we can't even initialize a bson_t we just say the error is at offset 0. - if (invalid_offset) *invalid_offset = 0u; + if (invalid_offset) + *invalid_offset = 0u; return {}; } diff --git a/src/bsoncxx/validate.hpp b/src/bsoncxx/validate.hpp index a80347dabb..bb3c2d1c75 100644 --- a/src/bsoncxx/validate.hpp +++ b/src/bsoncxx/validate.hpp @@ -65,7 +65,9 @@ validate(const std::uint8_t* data, std::size_t length); /// an unengaged optional if the document is invalid. /// BSONCXX_API stdx::optional BSONCXX_CALL -validate(const std::uint8_t* data, std::size_t length, const validator& validator, +validate(const std::uint8_t* data, + std::size_t length, + const validator& validator, std::size_t* invalid_offset = nullptr); /// /// A validator is used to enable or disable specific checks that can be diff --git a/src/bsoncxx/view_or_value.hpp b/src/bsoncxx/view_or_value.hpp index 7f50d9f553..86f54b36f9 100644 --- a/src/bsoncxx/view_or_value.hpp +++ b/src/bsoncxx/view_or_value.hpp @@ -57,8 +57,7 @@ class view_or_value { /// @param view /// A non-owning View. /// - BSONCXX_INLINE view_or_value(View view) : _view{view} { - } + BSONCXX_INLINE view_or_value(View view) : _view{view} {} /// /// Constructs a view_or_value from a Value type. This object owns the passed-in Value. @@ -66,15 +65,13 @@ class view_or_value { /// @param value /// A Value type. /// - BSONCXX_INLINE view_or_value(Value&& value) : _value(std::move(value)), _view(*_value) { - } + BSONCXX_INLINE view_or_value(Value&& value) : _value(std::move(value)), _view(*_value) {} /// /// Construct a view_or_value from a copied view_or_value. /// BSONCXX_INLINE view_or_value(const view_or_value& other) - : _value(other._value), _view(_value ? *_value : other._view) { - } + : _value(other._value), _view(_value ? *_value : other._view) {} /// /// Assign to this view_or_value from a copied view_or_value. diff --git a/src/mongocxx/client.cpp b/src/mongocxx/client.cpp index c4c77e62f6..6c4639e150 100644 --- a/src/mongocxx/client.cpp +++ b/src/mongocxx/client.cpp @@ -47,13 +47,13 @@ client::client(const class uri& uri, const options::client& options) libmongoc::client_set_ssl_opts(_get_impl().client_t, &mongoc_opts.first); } #else - if (uri.ssl() || options.ssl_opts()) throw exception{error_code::k_ssl_not_supported}; + if (uri.ssl() || options.ssl_opts()) + throw exception{error_code::k_ssl_not_supported}; #endif } client::client(void* implementation) - : _impl{stdx::make_unique(static_cast<::mongoc_client_t*>(implementation))} { -} + : _impl{stdx::make_unique(static_cast<::mongoc_client_t*>(implementation))} {} client::client(client&&) noexcept = default; client& client::operator=(client&&) noexcept = default; diff --git a/src/mongocxx/collection.cpp b/src/mongocxx/collection.cpp index 3d5caf2333..248e349546 100644 --- a/src/mongocxx/collection.cpp +++ b/src/mongocxx/collection.cpp @@ -67,7 +67,8 @@ using bsoncxx::builder::stream::concatenate; namespace { mongocxx::stdx::optional find_and_modify( - ::mongoc_collection_t* collection, view_or_value filter, + ::mongoc_collection_t* collection, + view_or_value filter, const ::mongoc_find_and_modify_opts_t* opts) { mongocxx::libbson::scoped_bson_t bson_filter{filter}; mongocxx::libbson::scoped_bson_t reply; @@ -100,8 +101,7 @@ mongocxx::stdx::optional find_and_modify( template class guard { public: - guard(T&& t) : _t{std::move(t)} { - } + guard(T&& t) : _t{std::move(t)} {} ~guard() { _t(); @@ -139,9 +139,11 @@ stdx::string_view collection::name() const { void collection::rename(bsoncxx::string::view_or_value new_name, bool drop_target_before_rename) { bson_error_t error; - auto result = libmongoc::collection_rename( - _get_impl().collection_t, _get_impl().database_name.c_str(), new_name.terminated().data(), - drop_target_before_rename, &error); + auto result = libmongoc::collection_rename(_get_impl().collection_t, + _get_impl().database_name.c_str(), + new_name.terminated().data(), + drop_target_before_rename, + &error); if (!result) { throw_exception(error); @@ -152,13 +154,13 @@ collection::collection(const database& database, bsoncxx::string::view_or_value : _impl(stdx::make_unique( libmongoc::database_get_collection(database._get_impl().database_t, collection_name.terminated().data()), - database.name(), database._get_impl().client_impl)) { -} + database.name(), + database._get_impl().client_impl)) {} collection::collection(const database& database, void* collection) - : _impl(stdx::make_unique(static_cast(collection), database.name(), - database._get_impl().client_impl)) { -} + : _impl(stdx::make_unique(static_cast(collection), + database.name(), + database._get_impl().client_impl)) {} collection::collection(const collection& c) { if (c) { @@ -374,7 +376,9 @@ cursor collection::aggregate(const pipeline& pipeline, const options::aggregate& return cursor(libmongoc::collection_aggregate(_get_impl().collection_t, static_cast<::mongoc_query_flags_t>(0), - stages.bson(), options_bson.bson(), rp_ptr)); + stages.bson(), + options_bson.bson(), + rp_ptr)); } stdx::optional collection::insert_one(view_or_value document, @@ -452,7 +456,8 @@ stdx::optional collection::replace_one(view_or_value filter return stdx::optional(result::replace_one(std::move(result.value()))); }; -stdx::optional collection::update_many(view_or_value filter, view_or_value update, +stdx::optional collection::update_many(view_or_value filter, + view_or_value update, const options::update& options) { options::bulk_write bulk_opts; bulk_opts.ordered(false); @@ -509,7 +514,8 @@ stdx::optional collection::delete_many( return stdx::optional(result::delete_result(std::move(result.value()))); } -stdx::optional collection::update_one(view_or_value filter, view_or_value update, +stdx::optional collection::update_one(view_or_value filter, + view_or_value update, const options::update& options) { options::bulk_write bulk_opts; bulk_opts.ordered(false); @@ -718,10 +724,14 @@ std::int64_t collection::count(view_or_value filter, const options::count& optio scoped_bson_t cmd_opts_bson{cmd_opts_builder.view()}; - auto result = libmongoc::collection_count_with_opts( - _get_impl().collection_t, static_cast(0), bson_filter.bson(), - options.skip().value_or(0), options.limit().value_or(0), cmd_opts_bson.bson(), rp_ptr, - &error); + auto result = libmongoc::collection_count_with_opts(_get_impl().collection_t, + static_cast(0), + bson_filter.bson(), + options.skip().value_or(0), + options.limit().value_or(0), + cmd_opts_bson.bson(), + rp_ptr, + &error); if (result < 0) { throw_exception(error); @@ -844,8 +854,8 @@ bsoncxx::document::value collection::create_index(view_or_value keys, opt.geo_options = &geo_opt; } - auto result = libmongoc::collection_create_index(_get_impl().collection_t, bson_keys.bson(), - &opt, &error); + auto result = libmongoc::collection_create_index( + _get_impl().collection_t, bson_keys.bson(), &opt, &error); if (!result) { throw_exception(error); @@ -864,7 +874,8 @@ bsoncxx::document::value collection::create_index(view_or_value keys, } } -cursor collection::distinct(bsoncxx::string::view_or_value field_name, view_or_value query, +cursor collection::distinct(bsoncxx::string::view_or_value field_name, + view_or_value query, const options::distinct& options) { // // Construct the distinct command and options. @@ -896,9 +907,12 @@ cursor collection::distinct(bsoncxx::string::view_or_value field_name, view_or_v scoped_bson_t command_bson{command_builder.extract()}; scoped_bson_t opts_bson{opts_builder.extract()}; - auto result = libmongoc::collection_read_command_with_opts( - _get_impl().collection_t, command_bson.bson(), rp_ptr, opts_bson.bson(), reply.bson(), - &error); + auto result = libmongoc::collection_read_command_with_opts(_get_impl().collection_t, + command_bson.bson(), + rp_ptr, + opts_bson.bson(), + reply.bson(), + &error); if (!result) { throw_exception(error); diff --git a/src/mongocxx/collection.hpp b/src/mongocxx/collection.hpp index 3255ac735f..7291b4cab3 100644 --- a/src/mongocxx/collection.hpp +++ b/src/mongocxx/collection.hpp @@ -184,7 +184,8 @@ class MONGOCXX_API collection { /// template MONGOCXX_INLINE stdx::optional bulk_write( - write_model_iterator_type begin, write_model_iterator_type end, + write_model_iterator_type begin, + write_model_iterator_type end, const options::bulk_write& options = options::bulk_write()); /// @@ -295,7 +296,8 @@ class MONGOCXX_API collection { /// @see https://docs.mongodb.com/master/reference/command/distinct/ /// - cursor distinct(bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, + cursor distinct(bsoncxx::string::view_or_value name, + bsoncxx::document::view_or_value filter, const options::distinct& options = options::distinct()); /// Drops this collection and all its contained documents from the database. @@ -388,7 +390,8 @@ class MONGOCXX_API collection { /// level set write concern - collection::write_concern(wc). /// stdx::optional find_one_and_replace( - bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, + bsoncxx::document::view_or_value filter, + bsoncxx::document::view_or_value replacement, const options::find_one_and_replace& options = options::find_one_and_replace()); /// @@ -411,7 +414,8 @@ class MONGOCXX_API collection { /// level set write concern - collection::write_concern(wc). /// stdx::optional find_one_and_update( - bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, + bsoncxx::document::view_or_value filter, + bsoncxx::document::view_or_value update, const options::find_one_and_update& options = options::find_one_and_update()); /// @@ -486,7 +490,8 @@ class MONGOCXX_API collection { /// TODO: document DocumentViewIterator concept or static assert template MONGOCXX_INLINE stdx::optional insert_many( - document_view_iterator_type begin, document_view_iterator_type end, + document_view_iterator_type begin, + document_view_iterator_type end, const options::insert& options = options::insert()); /// @@ -587,7 +592,8 @@ class MONGOCXX_API collection { /// @see https://docs.mongodb.com/master/reference/command/update/ /// stdx::optional replace_one( - bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, + bsoncxx::document::view_or_value filter, + bsoncxx::document::view_or_value replacement, const options::update& options = options::update()); /// @@ -678,7 +684,8 @@ MONGOCXX_INLINE stdx::optional collection::bulk_write( template MONGOCXX_INLINE stdx::optional collection::bulk_write( - write_model_iterator_type begin, write_model_iterator_type end, + write_model_iterator_type begin, + write_model_iterator_type end, const options::bulk_write& options) { class bulk_write writes(options); @@ -695,7 +702,8 @@ MONGOCXX_INLINE stdx::optional collection::insert_many( template MONGOCXX_INLINE stdx::optional collection::insert_many( - document_view_iterator_type begin, document_view_iterator_type end, + document_view_iterator_type begin, + document_view_iterator_type end, const options::insert& options) { auto op = std::for_each(begin, end, insert_many_builder{options}); diff --git a/src/mongocxx/cursor.cpp b/src/mongocxx/cursor.cpp index 922ee40644..db6e04df91 100644 --- a/src/mongocxx/cursor.cpp +++ b/src/mongocxx/cursor.cpp @@ -34,8 +34,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN cursor::cursor(void* cursor_ptr) - : _impl(stdx::make_unique(static_cast(cursor_ptr))) { -} + : _impl(stdx::make_unique(static_cast(cursor_ptr))) {} cursor::cursor(cursor&&) noexcept = default; cursor& cursor::operator=(cursor&&) noexcept = default; diff --git a/src/mongocxx/database.cpp b/src/mongocxx/database.cpp index f248a01b26..23ac5e8921 100644 --- a/src/mongocxx/database.cpp +++ b/src/mongocxx/database.cpp @@ -50,8 +50,8 @@ database::~database() = default; database::database(const class client& client, bsoncxx::string::view_or_value name) : _impl(stdx::make_unique( libmongoc::client_get_database(client._get_impl().client_t, name.terminated().data()), - &client._get_impl(), name.terminated().data())) { -} + &client._get_impl(), + name.terminated().data())) {} database::database(const database& d) { if (d) { @@ -94,8 +94,8 @@ bsoncxx::document::value database::run_command(bsoncxx::document::view_or_value bson_error_t error; reply_bson.flag_init(); - auto result = libmongoc::database_command_simple(_get_impl().database_t, command_bson.bson(), - NULL, reply_bson.bson(), &error); + auto result = libmongoc::database_command_simple( + _get_impl().database_t, command_bson.bson(), NULL, reply_bson.bson(), &error); if (!result) { throw_exception(reply_bson.steal(), error); @@ -241,8 +241,8 @@ void database::read_preference(class read_preference rp) { bool database::has_collection(bsoncxx::string::view_or_value name) const { bson_error_t error; - auto result = libmongoc::database_has_collection(_get_impl().database_t, - name.terminated().data(), &error); + auto result = libmongoc::database_has_collection( + _get_impl().database_t, name.terminated().data(), &error); if (error.domain != 0) { throw_exception(error); } diff --git a/src/mongocxx/exception/operation_exception.cpp b/src/mongocxx/exception/operation_exception.cpp index 2393cfd8bd..2f516430fc 100644 --- a/src/mongocxx/exception/operation_exception.cpp +++ b/src/mongocxx/exception/operation_exception.cpp @@ -25,8 +25,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN operation_exception::operation_exception(std::error_code ec, bsoncxx::document::value&& raw_server_error, std::string what_arg) - : exception(ec, what_arg), _raw_server_error{std::move(raw_server_error)} { -} + : exception(ec, what_arg), _raw_server_error{std::move(raw_server_error)} {} const stdx::optional& operation_exception::raw_server_error() const { return _raw_server_error; diff --git a/src/mongocxx/exception/operation_exception.hpp b/src/mongocxx/exception/operation_exception.hpp index 973546d7fb..22cfa7dd99 100644 --- a/src/mongocxx/exception/operation_exception.hpp +++ b/src/mongocxx/exception/operation_exception.hpp @@ -44,7 +44,8 @@ class MONGOCXX_API operation_exception : public exception { /// @param what_arg /// An optional message to be returned by `what`. /// - operation_exception(std::error_code ec, bsoncxx::document::value&& raw_server_error, + operation_exception(std::error_code ec, + bsoncxx::document::value&& raw_server_error, std::string what_arg = ""); /// diff --git a/src/mongocxx/exception/private/mongoc_error.hh b/src/mongocxx/exception/private/mongoc_error.hh index 46aedca9bb..ad12851747 100644 --- a/src/mongocxx/exception/private/mongoc_error.hh +++ b/src/mongocxx/exception/private/mongoc_error.hh @@ -28,17 +28,17 @@ inline std::error_code make_error_code(int code, int) { return {code, server_error_category()}; } -inline std::error_code make_error_code(const ::bson_error_t &error) { +inline std::error_code make_error_code(const ::bson_error_t& error) { return make_error_code(error.code, error.domain); } template -void throw_exception(const ::bson_error_t &error) { +void throw_exception(const ::bson_error_t& error) { throw exception_type{make_error_code(error), error.message}; } template -void throw_exception(bsoncxx::document::value raw_server_error, const ::bson_error_t &error) { +void throw_exception(bsoncxx::document::value raw_server_error, const ::bson_error_t& error) { throw exception_type{make_error_code(error), std::move(raw_server_error), error.message}; } diff --git a/src/mongocxx/hint.cpp b/src/mongocxx/hint.cpp index 37d436b004..0632b23450 100644 --- a/src/mongocxx/hint.cpp +++ b/src/mongocxx/hint.cpp @@ -21,11 +21,9 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN -hint::hint(bsoncxx::document::view_or_value index) : _index_doc(std::move(index)) { -} +hint::hint(bsoncxx::document::view_or_value index) : _index_doc(std::move(index)) {} -hint::hint(bsoncxx::string::view_or_value index) : _index_string(std::move(index)) { -} +hint::hint(bsoncxx::string::view_or_value index) : _index_string(std::move(index)) {} bsoncxx::types::value hint::to_value() const { if (_index_doc) { diff --git a/src/mongocxx/insert_many_builder.cpp b/src/mongocxx/insert_many_builder.cpp index 77dad1d55a..0f6a20da14 100644 --- a/src/mongocxx/insert_many_builder.cpp +++ b/src/mongocxx/insert_many_builder.cpp @@ -39,8 +39,7 @@ options::bulk_write make_bulk_write_options(const options::insert& insert_option } // namespace insert_many_builder::insert_many_builder(const options::insert& options) - : _writes{make_bulk_write_options(options)}, _inserted_ids{} { -} + : _writes{make_bulk_write_options(options)}, _inserted_ids{} {} void insert_many_builder::operator()(const bsoncxx::document::view& doc) { bsoncxx::builder::stream::document id_doc; diff --git a/src/mongocxx/instance.cpp b/src/mongocxx/instance.cpp index 53e49b19e3..57f58dc475 100644 --- a/src/mongocxx/instance.cpp +++ b/src/mongocxx/instance.cpp @@ -57,20 +57,22 @@ log_level convert_log_level(::mongoc_log_level_t mongoc_log_level) { } } -void null_log_handler(::mongoc_log_level_t, const char *, const char *, void *) { -} - -void user_log_handler(::mongoc_log_level_t mongoc_log_level, const char *log_domain, - const char *message, void *user_data) { - (*static_cast(user_data))(convert_log_level(mongoc_log_level), - stdx::string_view{log_domain}, stdx::string_view{message}); +void null_log_handler(::mongoc_log_level_t, const char*, const char*, void*) {} + +void user_log_handler(::mongoc_log_level_t mongoc_log_level, + const char* log_domain, + const char* message, + void* user_data) { + (*static_cast(user_data))(convert_log_level(mongoc_log_level), + stdx::string_view{log_domain}, + stdx::string_view{message}); } // A region of memory that acts as a sentintel value indicating that an instance object is being // destroyed. We only care about the address of this object, never its contents. typename std::aligned_storage::type sentinel; -std::atomic current_instance{nullptr}; +std::atomic current_instance{nullptr}; static_assert(std::is_standard_layout::value, "Must be standard layout"); #if (!defined(__GNUC__) || (defined(__clang__) && !defined(__GLIBCXX__))) || (__GNUC__ >= 5) @@ -115,30 +117,30 @@ class instance::impl { const std::unique_ptr _user_logger; }; -instance::instance() : instance(nullptr) { -} +instance::instance() : instance(nullptr) {} instance::instance(std::unique_ptr logger) { while (true) { - instance *expected = nullptr; - if (current_instance.compare_exchange_strong(expected, this)) break; - if (expected != reinterpret_cast(&sentinel)) + instance* expected = nullptr; + if (current_instance.compare_exchange_strong(expected, this)) + break; + if (expected != reinterpret_cast(&sentinel)) throw logic_error{error_code::k_instance_already_exists}; } _impl = stdx::make_unique(std::move(logger)); } -instance::instance(instance &&) noexcept = default; -instance &instance::operator=(instance &&) noexcept = default; +instance::instance(instance&&) noexcept = default; +instance& instance::operator=(instance&&) noexcept = default; instance::~instance() { - current_instance.store(reinterpret_cast(&sentinel)); + current_instance.store(reinterpret_cast(&sentinel)); _impl.reset(); current_instance.store(nullptr); } -instance &instance::current() { +instance& instance::current() { if (!current_instance.load()) { static instance the_instance; } diff --git a/src/mongocxx/logger.hpp b/src/mongocxx/logger.hpp index bc07e9e542..8da9e07156 100644 --- a/src/mongocxx/logger.hpp +++ b/src/mongocxx/logger.hpp @@ -64,7 +64,8 @@ class MONGOCXX_API logger { /// The domain of the current log message, such as 'client' /// @param message /// The text of the current log message. - virtual void operator()(log_level level, stdx::string_view domain, + virtual void operator()(log_level level, + stdx::string_view domain, stdx::string_view message) noexcept = 0; protected: diff --git a/src/mongocxx/model/delete_many.cpp b/src/mongocxx/model/delete_many.cpp index b62df31329..a4a48d82c8 100644 --- a/src/mongocxx/model/delete_many.cpp +++ b/src/mongocxx/model/delete_many.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace model { -delete_many::delete_many(bsoncxx::document::view_or_value filter) : _filter(std::move(filter)) { -} +delete_many::delete_many(bsoncxx::document::view_or_value filter) : _filter(std::move(filter)) {} const bsoncxx::document::view_or_value& delete_many::filter() const { return _filter; diff --git a/src/mongocxx/model/delete_one.cpp b/src/mongocxx/model/delete_one.cpp index 2fba88c98d..98af866ee1 100644 --- a/src/mongocxx/model/delete_one.cpp +++ b/src/mongocxx/model/delete_one.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace model { -delete_one::delete_one(bsoncxx::document::view_or_value filter) : _filter(std::move(filter)) { -} +delete_one::delete_one(bsoncxx::document::view_or_value filter) : _filter(std::move(filter)) {} const bsoncxx::document::view_or_value& delete_one::filter() const { return _filter; diff --git a/src/mongocxx/model/insert_one.cpp b/src/mongocxx/model/insert_one.cpp index 5ec6a35861..32bbf6c068 100644 --- a/src/mongocxx/model/insert_one.cpp +++ b/src/mongocxx/model/insert_one.cpp @@ -20,8 +20,8 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace model { -insert_one::insert_one(bsoncxx::document::view_or_value document) : _document(std::move(document)) { -} +insert_one::insert_one(bsoncxx::document::view_or_value document) + : _document(std::move(document)) {} const bsoncxx::document::view_or_value& insert_one::document() const { return _document; diff --git a/src/mongocxx/model/replace_one.cpp b/src/mongocxx/model/replace_one.cpp index bb52660d14..85dd8fd502 100644 --- a/src/mongocxx/model/replace_one.cpp +++ b/src/mongocxx/model/replace_one.cpp @@ -22,8 +22,7 @@ namespace model { replace_one::replace_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement) - : _filter(std::move(filter)), _replacement(std::move(replacement)) { -} + : _filter(std::move(filter)), _replacement(std::move(replacement)) {} const bsoncxx::document::view_or_value& replace_one::filter() const { return _filter; diff --git a/src/mongocxx/model/update_many.cpp b/src/mongocxx/model/update_many.cpp index ecda3fe608..084c97f83c 100644 --- a/src/mongocxx/model/update_many.cpp +++ b/src/mongocxx/model/update_many.cpp @@ -22,8 +22,7 @@ namespace model { update_many::update_many(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update) - : _filter(std::move(filter)), _update(std::move(update)) { -} + : _filter(std::move(filter)), _update(std::move(update)) {} const bsoncxx::document::view_or_value& update_many::filter() const { return _filter; diff --git a/src/mongocxx/model/update_one.cpp b/src/mongocxx/model/update_one.cpp index 4070ee8970..a0f6106754 100644 --- a/src/mongocxx/model/update_one.cpp +++ b/src/mongocxx/model/update_one.cpp @@ -22,8 +22,7 @@ namespace model { update_one::update_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update) - : _filter(std::move(filter)), _update(std::move(update)) { -} + : _filter(std::move(filter)), _update(std::move(update)) {} const bsoncxx::document::view_or_value& update_one::filter() const { return _filter; diff --git a/src/mongocxx/options/bulk_write.cpp b/src/mongocxx/options/bulk_write.cpp index 8b49b30d75..36398086c3 100644 --- a/src/mongocxx/options/bulk_write.cpp +++ b/src/mongocxx/options/bulk_write.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace options { -bulk_write::bulk_write() : _ordered(true) { -} +bulk_write::bulk_write() : _ordered(true) {} bulk_write& bulk_write::ordered(bool ordered) { _ordered = ordered; diff --git a/src/mongocxx/pipeline.cpp b/src/mongocxx/pipeline.cpp index 24c368d0ec..009301e9be 100644 --- a/src/mongocxx/pipeline.cpp +++ b/src/mongocxx/pipeline.cpp @@ -25,8 +25,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN using namespace bsoncxx::builder::stream; -pipeline::pipeline() : _impl(stdx::make_unique()) { -} +pipeline::pipeline() : _impl(stdx::make_unique()) {} pipeline::pipeline(pipeline&&) noexcept = default; pipeline& pipeline::operator=(pipeline&&) noexcept = default; diff --git a/src/mongocxx/pool.cpp b/src/mongocxx/pool.cpp index 0eb3ad6043..94b402bb62 100644 --- a/src/mongocxx/pool.cpp +++ b/src/mongocxx/pool.cpp @@ -64,7 +64,8 @@ pool::entry pool::acquire() { stdx::optional pool::try_acquire() { auto cli = libmongoc::client_pool_try_pop(_impl->client_pool_t); - if (!cli) return stdx::nullopt; + if (!cli) + return stdx::nullopt; return pool::entry{new client(cli), [this](client* client) { _release(client); }}; } diff --git a/src/mongocxx/private/bulk_write.hh b/src/mongocxx/private/bulk_write.hh index 1c74c958a1..19c2ff2b33 100644 --- a/src/mongocxx/private/bulk_write.hh +++ b/src/mongocxx/private/bulk_write.hh @@ -24,8 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class bulk_write::impl { public: - impl(mongoc_bulk_operation_t* op) : operation_t(op) { - } + impl(mongoc_bulk_operation_t* op) : operation_t(op) {} ~impl() { libmongoc::bulk_operation_destroy(operation_t); diff --git a/src/mongocxx/private/client.hh b/src/mongocxx/private/client.hh index cca682454d..6eda16dbdf 100644 --- a/src/mongocxx/private/client.hh +++ b/src/mongocxx/private/client.hh @@ -27,8 +27,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class client::impl { public: - impl(mongoc_client_t* client) : client_t(client) { - } + impl(mongoc_client_t* client) : client_t(client) {} ~impl() { libmongoc::client_destroy(client_t); diff --git a/src/mongocxx/private/collection.hh b/src/mongocxx/private/collection.hh index d1ccbd5fe6..acb75b147b 100644 --- a/src/mongocxx/private/collection.hh +++ b/src/mongocxx/private/collection.hh @@ -31,16 +31,15 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class collection::impl { public: - impl(mongoc_collection_t* collection, stdx::string_view database_name, + impl(mongoc_collection_t* collection, + stdx::string_view database_name, const class client::impl* client) - : collection_t(collection), database_name(std::move(database_name)), client_impl(client) { - } + : collection_t(collection), database_name(std::move(database_name)), client_impl(client) {} impl(const impl& i) : collection_t{libmongoc::collection_copy(i.collection_t)}, database_name{i.database_name}, - client_impl{i.client_impl} { - } + client_impl{i.client_impl} {} // This method is deleted because we only use the copy constructor. impl& operator=(const impl& i) = delete; diff --git a/src/mongocxx/private/cursor.hh b/src/mongocxx/private/cursor.hh index a0a90e9b2d..8415cd1888 100644 --- a/src/mongocxx/private/cursor.hh +++ b/src/mongocxx/private/cursor.hh @@ -30,8 +30,7 @@ class cursor::impl { enum class state { k_pending = 0, k_started = 1, k_dead = 2 }; impl(mongoc_cursor_t* cursor) - : cursor_t(cursor), status{cursor ? state::k_pending : state::k_dead} { - } + : cursor_t(cursor), status{cursor ? state::k_pending : state::k_dead} {} ~impl() { libmongoc::cursor_destroy(cursor_t); diff --git a/src/mongocxx/private/database.hh b/src/mongocxx/private/database.hh index 549fd44656..d578676cd9 100644 --- a/src/mongocxx/private/database.hh +++ b/src/mongocxx/private/database.hh @@ -28,14 +28,12 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class database::impl { public: impl(mongoc_database_t* db, const class client::impl* client, std::string name) - : database_t(db), client_impl(client), name(std::move(name)) { - } + : database_t(db), client_impl(client), name(std::move(name)) {} impl(const impl& i) : database_t{libmongoc::database_copy(i.database_t)}, client_impl{i.client_impl}, - name{i.name} { - } + name{i.name} {} // This method is deleted because we only use the copy constructor. impl& operator=(const impl& i) = delete; diff --git a/src/mongocxx/private/libbson.cpp b/src/mongocxx/private/libbson.cpp index 18f35c9967..2e6ce8dfc0 100644 --- a/src/mongocxx/private/libbson.cpp +++ b/src/mongocxx/private/libbson.cpp @@ -65,8 +65,7 @@ void scoped_bson_t::flag_init() { _is_initialized = true; } -scoped_bson_t::scoped_bson_t() : _is_initialized(false) { -} +scoped_bson_t::scoped_bson_t() : _is_initialized(false) {} scoped_bson_t::~scoped_bson_t() { if (_is_initialized) { diff --git a/src/mongocxx/private/pool.hh b/src/mongocxx/private/pool.hh index 1da60e5edd..9c092fd88e 100644 --- a/src/mongocxx/private/pool.hh +++ b/src/mongocxx/private/pool.hh @@ -27,8 +27,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class pool::impl { public: - impl(mongoc_client_pool_t* pool) : client_pool_t(pool) { - } + impl(mongoc_client_pool_t* pool) : client_pool_t(pool) {} ~impl() { libmongoc::client_pool_destroy(client_pool_t); diff --git a/src/mongocxx/private/read_concern.hh b/src/mongocxx/private/read_concern.hh index 79ac79844e..5e35410453 100644 --- a/src/mongocxx/private/read_concern.hh +++ b/src/mongocxx/private/read_concern.hh @@ -24,8 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class read_concern::impl { public: - impl(::mongoc_read_concern_t* read_concern) : read_concern_t{read_concern} { - } + impl(::mongoc_read_concern_t* read_concern) : read_concern_t{read_concern} {} ~impl() { libmongoc::read_concern_destroy(read_concern_t); diff --git a/src/mongocxx/private/read_preference.hh b/src/mongocxx/private/read_preference.hh index efb07298d9..1652730198 100644 --- a/src/mongocxx/private/read_preference.hh +++ b/src/mongocxx/private/read_preference.hh @@ -24,8 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class read_preference::impl { public: - impl(mongoc_read_prefs_t* read_pref) : read_preference_t(read_pref) { - } + impl(mongoc_read_prefs_t* read_pref) : read_preference_t(read_pref) {} ~impl() { libmongoc::read_prefs_destroy(read_preference_t); diff --git a/src/mongocxx/private/uri.hh b/src/mongocxx/private/uri.hh index 0d82d5bbaf..a1a95f2b6f 100644 --- a/src/mongocxx/private/uri.hh +++ b/src/mongocxx/private/uri.hh @@ -24,8 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class uri::impl { public: - impl(mongoc_uri_t* uri) : uri_t(uri) { - } + impl(mongoc_uri_t* uri) : uri_t(uri) {} ~impl() { libmongoc::uri_destroy(uri_t); } diff --git a/src/mongocxx/private/write_concern.hh b/src/mongocxx/private/write_concern.hh index 27d31aef75..2eca50a99d 100644 --- a/src/mongocxx/private/write_concern.hh +++ b/src/mongocxx/private/write_concern.hh @@ -24,8 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN class write_concern::impl { public: - impl(mongoc_write_concern_t* write_concern) : write_concern_t(write_concern) { - } + impl(mongoc_write_concern_t* write_concern) : write_concern_t(write_concern) {} ~impl() { libmongoc::write_concern_destroy(write_concern_t); diff --git a/src/mongocxx/read_concern.cpp b/src/mongocxx/read_concern.cpp index bb0f548889..fc4485118d 100644 --- a/src/mongocxx/read_concern.cpp +++ b/src/mongocxx/read_concern.cpp @@ -25,19 +25,16 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN -read_concern::read_concern() : _impl{stdx::make_unique(libmongoc::read_concern_new())} { -} +read_concern::read_concern() : _impl{stdx::make_unique(libmongoc::read_concern_new())} {} read_concern::read_concern(std::unique_ptr&& implementation) - : _impl{std::move(implementation)} { -} + : _impl{std::move(implementation)} {} read_concern::read_concern(read_concern&&) noexcept = default; read_concern& read_concern::operator=(read_concern&&) noexcept = default; read_concern::read_concern(const read_concern& other) - : _impl(stdx::make_unique(libmongoc::read_concern_copy(other._impl->read_concern_t))) { -} + : _impl(stdx::make_unique(libmongoc::read_concern_copy(other._impl->read_concern_t))) {} read_concern& read_concern::operator=(const read_concern& other) { _impl = stdx::make_unique(libmongoc::read_concern_copy(other._impl->read_concern_t)); diff --git a/src/mongocxx/read_preference.cpp b/src/mongocxx/read_preference.cpp index 89840c02e4..274b2d3a7d 100644 --- a/src/mongocxx/read_preference.cpp +++ b/src/mongocxx/read_preference.cpp @@ -30,8 +30,7 @@ read_preference::read_preference(read_preference&&) noexcept = default; read_preference& read_preference::operator=(read_preference&&) noexcept = default; read_preference::read_preference(const read_preference& other) - : _impl(stdx::make_unique(libmongoc::read_prefs_copy(other._impl->read_preference_t))) { -} + : _impl(stdx::make_unique(libmongoc::read_prefs_copy(other._impl->read_preference_t))) {} read_preference& read_preference::operator=(const read_preference& other) { _impl.reset(stdx::make_unique(libmongoc::read_prefs_copy(other._impl->read_preference_t)) @@ -45,8 +44,7 @@ read_preference::read_preference(std::unique_ptr&& implementation) { read_preference::read_preference(read_mode mode) : _impl(stdx::make_unique( - libmongoc::read_prefs_new(static_cast(mode)))) { -} + libmongoc::read_prefs_new(static_cast(mode)))) {} read_preference::read_preference(read_mode mode, bsoncxx::document::view_or_value tags) : read_preference(mode) { diff --git a/src/mongocxx/result/bulk_write.cpp b/src/mongocxx/result/bulk_write.cpp index 697da5e4ab..b59de19642 100644 --- a/src/mongocxx/result/bulk_write.cpp +++ b/src/mongocxx/result/bulk_write.cpp @@ -20,8 +20,8 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace result { -bulk_write::bulk_write(bsoncxx::document::value raw_response) : _response(std::move(raw_response)) { -} +bulk_write::bulk_write(bsoncxx::document::value raw_response) + : _response(std::move(raw_response)) {} std::int32_t bulk_write::inserted_count() const { return view()["nInserted"].get_int32(); diff --git a/src/mongocxx/result/delete.cpp b/src/mongocxx/result/delete.cpp index 66d8167be0..e169d566d9 100644 --- a/src/mongocxx/result/delete.cpp +++ b/src/mongocxx/result/delete.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace result { -delete_result::delete_result(result::bulk_write result) : _result(std::move(result)) { -} +delete_result::delete_result(result::bulk_write result) : _result(std::move(result)) {} const result::bulk_write& delete_result::result() const { return _result; diff --git a/src/mongocxx/result/insert_one.cpp b/src/mongocxx/result/insert_one.cpp index a7a3809191..c39a0b73d2 100644 --- a/src/mongocxx/result/insert_one.cpp +++ b/src/mongocxx/result/insert_one.cpp @@ -26,8 +26,7 @@ insert_one::insert_one(result::bulk_write result, bsoncxx::types::value inserted : _result(std::move(result)), _inserted_id_owned(bsoncxx::builder::stream::array{} << inserted_id << bsoncxx::builder::stream::finalize), - _inserted_id(_inserted_id_owned.view()[0].get_value()) { -} + _inserted_id(_inserted_id_owned.view()[0].get_value()) {} const result::bulk_write& insert_one::result() const { return _result; diff --git a/src/mongocxx/result/replace_one.cpp b/src/mongocxx/result/replace_one.cpp index a6ba639b72..a7bd002802 100644 --- a/src/mongocxx/result/replace_one.cpp +++ b/src/mongocxx/result/replace_one.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace result { -replace_one::replace_one(result::bulk_write result) : _result(std::move(result)) { -} +replace_one::replace_one(result::bulk_write result) : _result(std::move(result)) {} const result::bulk_write& replace_one::result() const { return _result; diff --git a/src/mongocxx/result/update.cpp b/src/mongocxx/result/update.cpp index 23a1f86da8..c4c1fe0b7d 100644 --- a/src/mongocxx/result/update.cpp +++ b/src/mongocxx/result/update.cpp @@ -20,8 +20,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN namespace result { -update::update(result::bulk_write result) : _result(std::move(result)) { -} +update::update(result::bulk_write result) : _result(std::move(result)) {} const result::bulk_write& update::result() const { return _result; diff --git a/src/mongocxx/test/bulk_write.cpp b/src/mongocxx/test/bulk_write.cpp index 588ce39e09..81e1bee583 100644 --- a/src/mongocxx/test/bulk_write.cpp +++ b/src/mongocxx/test/bulk_write.cpp @@ -66,8 +66,7 @@ TEST_CASE("destruction of a bulk_write will destroy mongoc operation", "[bulk_wr class insert_functor { public: insert_functor(bool* called, bsoncxx::document::view document) - : _called{called}, _document{document} { - } + : _called{called}, _document{document} {} void operator()(mongoc_bulk_operation_t*, const bson_t* document) { *_called = true; @@ -82,11 +81,13 @@ class insert_functor { class update_functor { public: update_functor(bool* called, bsoncxx::document::view filter, bsoncxx::document::view update) - : _called{called}, _filter{filter}, _update{update} { - } + : _called{called}, _filter{filter}, _update{update} {} - void operator()(mongoc_bulk_operation_t*, const bson_t* filter, const bson_t* update, - const bson_t* options, bson_error_t*) { + void operator()(mongoc_bulk_operation_t*, + const bson_t* filter, + const bson_t* update, + const bson_t* options, + bson_error_t*) { *_called = true; REQUIRE(bson_get_data(filter) == _filter.data()); REQUIRE(bson_get_data(update) == _update.data()); @@ -131,10 +132,11 @@ class update_functor { class delete_functor { public: delete_functor(bool* called, bsoncxx::document::view filter) - : _called{called}, _filter{filter} { - } + : _called{called}, _filter{filter} {} - void operator()(mongoc_bulk_operation_t*, const bson_t* filter, const bson_t* options, + void operator()(mongoc_bulk_operation_t*, + const bson_t* filter, + const bson_t* options, bson_error_t*) { *_called = true; REQUIRE(bson_get_data(filter) == _filter.data()); diff --git a/src/mongocxx/test/collection.cpp b/src/mongocxx/test/collection.cpp index 6980b51c93..c2b0341695 100644 --- a/src/mongocxx/test/collection.cpp +++ b/src/mongocxx/test/collection.cpp @@ -860,13 +860,13 @@ TEST_CASE("CRUD functionality", "[driver::collection]") { << "FOO"; if (test_util::supports_collation(mongodb_client)) { - auto doc = coll.find_one_and_replace(collation_criteria.view(), replacement.view(), - options); + auto doc = coll.find_one_and_replace( + collation_criteria.view(), replacement.view(), options); REQUIRE(doc); REQUIRE(doc->view()["x"].get_utf8().value == stdx::string_view{"foo"}); } else { - REQUIRE_THROWS_AS(coll.find_one_and_replace(collation_criteria.view(), - replacement.view(), options), + REQUIRE_THROWS_AS(coll.find_one_and_replace( + collation_criteria.view(), replacement.view(), options), write_exception); } } @@ -995,7 +995,9 @@ TEST_CASE("CRUD functionality", "[driver::collection]") { auto get_results = [](cursor&& cursor) { std::vector results; - std::transform(cursor.begin(), cursor.end(), std::back_inserter(results), + std::transform(cursor.begin(), + cursor.end(), + std::back_inserter(results), [](bsoncxx::document::view v) { return bsoncxx::document::value{v}; }); return results; }; diff --git a/src/mongocxx/test/collection_mocked.cpp b/src/mongocxx/test/collection_mocked.cpp index f50f3ef6a9..c75ef9e596 100644 --- a/src/mongocxx/test/collection_mocked.cpp +++ b/src/mongocxx/test/collection_mocked.cpp @@ -91,13 +91,16 @@ TEST_CASE("Collection", "[collection]") { std::string expected_rename; bool expected_drop; - collection_rename->interpose([&expected_rename, &expected_drop]( - ::mongoc_collection_t*, const char*, const char* new_name, - bool drop_target_before_rename, ::bson_error_t*) { - REQUIRE(expected_rename == std::string{new_name}); - REQUIRE(expected_drop == drop_target_before_rename); - return true; - }); + collection_rename->interpose( + [&expected_rename, &expected_drop](::mongoc_collection_t*, + const char*, + const char* new_name, + bool drop_target_before_rename, + ::bson_error_t*) { + REQUIRE(expected_rename == std::string{new_name}); + REQUIRE(expected_drop == drop_target_before_rename); + return true; + }); SECTION("with drop_target_before_rename false") { expected_rename = "the_best_collection"; @@ -128,8 +131,10 @@ TEST_CASE("Collection", "[collection]") { pipeline pipe; options::aggregate opts; - collection_aggregate->interpose([&](mongoc_collection_t*, mongoc_query_flags_t flags, - const bson_t* pipeline, const bson_t* options, + collection_aggregate->interpose([&](mongoc_collection_t*, + mongoc_query_flags_t flags, + const bson_t* pipeline, + const bson_t* options, const mongoc_read_prefs_t*) -> mongoc_cursor_t* { collection_aggregate_called = true; REQUIRE(flags == MONGOC_QUERY_NONE); @@ -155,7 +160,8 @@ TEST_CASE("Collection", "[collection]") { else REQUIRE(o.find("maxTimeMS") == o.end()); - if (opts.use_cursor()) REQUIRE(o.find("cursor") != o.end()); + if (opts.use_cursor()) + REQUIRE(o.find("cursor") != o.end()); if (opts.batch_size()) { REQUIRE(o.find("cursor") != o.end()); @@ -176,8 +182,7 @@ TEST_CASE("Collection", "[collection]") { << "bar" << builder::stream::finalize); pipe.sort(builder::stream::document{} << "foo" << 1 << builder::stream::finalize); - SECTION("With default options") { - } + SECTION("With default options") {} SECTION("With some options") { opts.allow_disk_use(expected_allow_disk_use); @@ -200,10 +205,14 @@ TEST_CASE("Collection", "[collection]") { const bson_t* expected_opts = nullptr; - collection_count_with_opts->interpose([&](mongoc_collection_t*, mongoc_query_flags_t flags, - const bson_t* query, int64_t skip, int64_t limit, + collection_count_with_opts->interpose([&](mongoc_collection_t*, + mongoc_query_flags_t flags, + const bson_t* query, + int64_t skip, + int64_t limit, const bson_t* cmd_opts, - const mongoc_read_prefs_t*, bson_error_t* error) { + const mongoc_read_prefs_t*, + bson_error_t* error) { collection_count_called = true; REQUIRE(flags == MONGOC_QUERY_NONE); REQUIRE(bson_get_data(query) == filter_doc.view().data()); @@ -213,12 +222,15 @@ TEST_CASE("Collection", "[collection]") { REQUIRE(bson_equal(cmd_opts, expected_opts)); } - if (success) return 123; + if (success) + return 123; // The caller expects the bson_error_t to have been // initialized by the call to count in the event of an // error. - bson_set_error(error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, + bson_set_error(error, + MONGOC_ERROR_COMMAND, + MONGOC_ERROR_COMMAND_INVALID_ARG, "expected error from mock"); return -1; @@ -280,8 +292,10 @@ TEST_CASE("Collection", "[collection]") { << "foo" << "bar" << builder::stream::finalize; - collection_create_index->interpose([&](mongoc_collection_t*, const bson_t*, - const mongoc_index_opt_t* opt, bson_error_t* error) { + collection_create_index->interpose([&](mongoc_collection_t*, + const bson_t*, + const mongoc_index_opt_t* opt, + bson_error_t* error) { collection_create_index_called = true; if (options.unique()) { REQUIRE(opt->unique == expected_unique); @@ -295,7 +309,9 @@ TEST_CASE("Collection", "[collection]") { } if (!success) - bson_set_error(error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, + bson_set_error(error, + MONGOC_ERROR_COMMAND, + MONGOC_ERROR_COMMAND_INVALID_ARG, "expected error from mock"); return success; @@ -355,7 +371,9 @@ TEST_CASE("Collection", "[collection]") { collection_drop_called = true; if (!success) - bson_set_error(error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, + bson_set_error(error, + MONGOC_ERROR_COMMAND, + MONGOC_ERROR_COMMAND_INVALID_ARG, "expected error from mock"); return success; @@ -385,7 +403,8 @@ TEST_CASE("Collection", "[collection]") { mongocxx::stdx::optional expected_no_cursor_timeout; mongocxx::stdx::optional expected_sort{}; - collection_find_with_opts->interpose([&](mongoc_collection_t*, const bson_t* filter, + collection_find_with_opts->interpose([&](mongoc_collection_t*, + const bson_t* filter, const bson_t* opts, const mongoc_read_prefs_t* read_prefs) { collection_find_called = true; @@ -575,36 +594,37 @@ TEST_CASE("Collection", "[collection]") { SECTION("Update One", "[collection::update_one]") { bool upsert_option = false; - bulk_operation_update_one_with_opts->interpose( - [&](mongoc_bulk_operation_t*, const bson_t* query, const bson_t* update, - const bson_t* options, bson_error_t*) { - bulk_operation_op_called = true; - REQUIRE(bson_get_data(query) == filter_doc.view().data()); - REQUIRE(bson_get_data(update) == modification_doc.view().data()); - - bsoncxx::document::view options_view{bson_get_data(options), options->len}; - - bsoncxx::document::element upsert = options_view["upsert"]; - if (upsert_option) { + bulk_operation_update_one_with_opts->interpose([&](mongoc_bulk_operation_t*, + const bson_t* query, + const bson_t* update, + const bson_t* options, + bson_error_t*) { + bulk_operation_op_called = true; + REQUIRE(bson_get_data(query) == filter_doc.view().data()); + REQUIRE(bson_get_data(update) == modification_doc.view().data()); + + bsoncxx::document::view options_view{bson_get_data(options), options->len}; + + bsoncxx::document::element upsert = options_view["upsert"]; + if (upsert_option) { + REQUIRE(upsert); + REQUIRE(upsert.type() == bsoncxx::type::k_bool); + REQUIRE(upsert.get_bool().value); + } else { + // Allow either no "upsert" option, or an "upsert" option set to false. + if (upsert) { REQUIRE(upsert); REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(upsert.get_bool().value); - } else { - // Allow either no "upsert" option, or an "upsert" option set to false. - if (upsert) { - REQUIRE(upsert); - REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(!upsert.get_bool().value); - } + REQUIRE(!upsert.get_bool().value); } + } - return true; - }); + return true; + }); options::update options; - SECTION("Default Options") { - } + SECTION("Default Options") {} SECTION("Upsert true") { upsert_option = true; @@ -633,31 +653,33 @@ TEST_CASE("Collection", "[collection]") { SECTION("Update Many", "[collection::update_many]") { bool upsert_option; - bulk_operation_update_many_with_opts->interpose( - [&](mongoc_bulk_operation_t*, const bson_t* query, const bson_t* update, - const bson_t* options, bson_error_t*) { - bulk_operation_op_called = true; - REQUIRE(bson_get_data(query) == filter_doc.view().data()); - REQUIRE(bson_get_data(update) == modification_doc.view().data()); - - bsoncxx::document::view options_view{bson_get_data(options), options->len}; - - bsoncxx::document::element upsert = options_view["upsert"]; - if (upsert_option) { + bulk_operation_update_many_with_opts->interpose([&](mongoc_bulk_operation_t*, + const bson_t* query, + const bson_t* update, + const bson_t* options, + bson_error_t*) { + bulk_operation_op_called = true; + REQUIRE(bson_get_data(query) == filter_doc.view().data()); + REQUIRE(bson_get_data(update) == modification_doc.view().data()); + + bsoncxx::document::view options_view{bson_get_data(options), options->len}; + + bsoncxx::document::element upsert = options_view["upsert"]; + if (upsert_option) { + REQUIRE(upsert); + REQUIRE(upsert.type() == bsoncxx::type::k_bool); + REQUIRE(upsert.get_bool().value); + } else { + // Allow either no "upsert" option, or an "upsert" option set to false. + if (upsert) { REQUIRE(upsert); REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(upsert.get_bool().value); - } else { - // Allow either no "upsert" option, or an "upsert" option set to false. - if (upsert) { - REQUIRE(upsert); - REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(!upsert.get_bool().value); - } + REQUIRE(!upsert.get_bool().value); } + } - return true; - }); + return true; + }); options::update options; @@ -681,31 +703,33 @@ TEST_CASE("Collection", "[collection]") { SECTION("Replace One", "[collection::replace_one]") { bool upsert_option; - bulk_operation_replace_one_with_opts->interpose( - [&](mongoc_bulk_operation_t*, const bson_t* query, const bson_t* update, - const bson_t* options, bson_error_t*) { - bulk_operation_op_called = true; - REQUIRE(bson_get_data(query) == filter_doc.view().data()); - REQUIRE(bson_get_data(update) == modification_doc.view().data()); - - bsoncxx::document::view options_view{bson_get_data(options), options->len}; - - bsoncxx::document::element upsert = options_view["upsert"]; - if (upsert_option) { + bulk_operation_replace_one_with_opts->interpose([&](mongoc_bulk_operation_t*, + const bson_t* query, + const bson_t* update, + const bson_t* options, + bson_error_t*) { + bulk_operation_op_called = true; + REQUIRE(bson_get_data(query) == filter_doc.view().data()); + REQUIRE(bson_get_data(update) == modification_doc.view().data()); + + bsoncxx::document::view options_view{bson_get_data(options), options->len}; + + bsoncxx::document::element upsert = options_view["upsert"]; + if (upsert_option) { + REQUIRE(upsert); + REQUIRE(upsert.type() == bsoncxx::type::k_bool); + REQUIRE(upsert.get_bool().value); + } else { + // Allow either no "upsert" option, or an "upsert" option set to false. + if (upsert) { REQUIRE(upsert); REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(upsert.get_bool().value); - } else { - // Allow either no "upsert" option, or an "upsert" option set to false. - if (upsert) { - REQUIRE(upsert); - REQUIRE(upsert.type() == bsoncxx::type::k_bool); - REQUIRE(!upsert.get_bool().value); - } + REQUIRE(!upsert.get_bool().value); } + } - return true; - }); + return true; + }); options::update options; @@ -771,15 +795,17 @@ TEST_CASE("Collection", "[collection]") { libbson::scoped_bson_t return_bson{return_doc.view()}; bsoncxx::stdx::optional fam_result; - collection_find_and_modify_with_opts->interpose( - [&](::mongoc_collection_t*, const ::bson_t* filter, - const ::mongoc_find_and_modify_opts_t*, ::bson_t* reply, ::bson_error_t*) { - fam_called = true; - document::view filter_view{bson_get_data(filter), filter->len}; - REQUIRE(expected_filter == filter_view); - ::bson_copy_to(return_bson.bson(), reply); - return true; - }); + collection_find_and_modify_with_opts->interpose([&](::mongoc_collection_t*, + const ::bson_t* filter, + const ::mongoc_find_and_modify_opts_t*, + ::bson_t* reply, + ::bson_error_t*) { + fam_called = true; + document::view filter_view{bson_get_data(filter), filter->len}; + REQUIRE(expected_filter == filter_view); + ::bson_copy_to(return_bson.bson(), reply); + return true; + }); SECTION("Delete", "[collection::find_one_and_delete]") { options::find_one_and_delete opts{}; @@ -841,8 +867,8 @@ TEST_CASE("Collection", "[collection]") { opts.upsert(true); opts.return_document(options::return_document::k_after); - fam_result = mongo_coll.find_one_and_update(expected_filter, - expected_find_and_modify_opts_update, opts); + fam_result = mongo_coll.find_one_and_update( + expected_filter, expected_find_and_modify_opts_update, opts); } REQUIRE(fam_called); diff --git a/src/mongocxx/test/database.cpp b/src/mongocxx/test/database.cpp index cea1216449..80c70a16e5 100644 --- a/src/mongocxx/test/database.cpp +++ b/src/mongocxx/test/database.cpp @@ -118,7 +118,9 @@ TEST_CASE("A database", "[database]") { SECTION("throws an exception when dropping causes an error") { database_drop->interpose([&](mongoc_database_t*, bson_error_t* error) { - bson_set_error(error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, + bson_set_error(error, + MONGOC_ERROR_COMMAND, + MONGOC_ERROR_COMMAND_INVALID_ARG, "expected error from mock"); return false; }); @@ -130,7 +132,9 @@ TEST_CASE("A database", "[database]") { SECTION("throws an exception when has_collection causes an error") { database_has_collection->interpose( [](mongoc_database_t*, const char*, bson_error_t* error) { - bson_set_error(error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, + bson_set_error(error, + MONGOC_ERROR_COMMAND, + MONGOC_ERROR_COMMAND_INVALID_ARG, "expected error from mock"); return false; }); @@ -262,8 +266,10 @@ TEST_CASE("A database", "[database]") { << "foo" << 5 << bsoncxx::builder::stream::finalize; libbson::scoped_bson_t bson_doc{doc.view()}; - database_command_simple->interpose([&](mongoc_database_t*, const bson_t*, - const mongoc_read_prefs_t*, bson_t* reply, + database_command_simple->interpose([&](mongoc_database_t*, + const bson_t*, + const mongoc_read_prefs_t*, + bson_t* reply, bson_error_t*) { called = true; ::bson_copy_to(bson_doc.bson(), reply); @@ -435,7 +441,8 @@ TEST_CASE("Database integration tests", "[database]") { SECTION("View creation with a pipeline") { collection view = database.create_view( - view_name, collection_name, + view_name, + collection_name, options::create_view().pipeline(std::move(pipeline({}).limit(1)))); if (test_util::get_max_wire_version(mongo_client) >= 5) { diff --git a/src/mongocxx/test/instance.cpp b/src/mongocxx/test/instance.cpp index c5dbb73217..e3738ffaf8 100644 --- a/src/mongocxx/test/instance.cpp +++ b/src/mongocxx/test/instance.cpp @@ -31,10 +31,10 @@ class test_log_handler : public logger { public: using event = std::tuple; - test_log_handler(std::vector* events) : _events(events) { - } + test_log_handler(std::vector* events) : _events(events) {} - void operator()(log_level level, stdx::string_view domain, + void operator()(log_level level, + stdx::string_view domain, stdx::string_view message) noexcept final { if (level == log_level::k_error) _events->emplace_back(level, std::string(domain), std::string(message)); diff --git a/src/mongocxx/test/options/index.cpp b/src/mongocxx/test/options/index.cpp index 11a768f4d7..f56e2efa45 100644 --- a/src/mongocxx/test/options/index.cpp +++ b/src/mongocxx/test/options/index.cpp @@ -51,7 +51,7 @@ TEST_CASE("index", "[index][option]") { CHECK_OPTIONAL_ARGUMENT(idx, twod_location_max, 90.0); CHECK_OPTIONAL_ARGUMENT(idx, haystack_bucket_size, 90.0); CHECK_OPTIONAL_ARGUMENT_WITHOUT_EQUALITY(idx, weights, weights.view()); - CHECK_OPTIONAL_ARGUMENT_WITHOUT_EQUALITY(idx, partial_filter_expression, - partial_filter_expression.view()); + CHECK_OPTIONAL_ARGUMENT_WITHOUT_EQUALITY( + idx, partial_filter_expression, partial_filter_expression.view()); REQUIRE_NOTHROW(idx.storage_options(std::move(storage))); } diff --git a/src/mongocxx/test_util/mock.hh b/src/mongocxx/test_util/mock.hh index d2a0d4e17d..de1c223e7f 100644 --- a/src/mongocxx/test_util/mock.hh +++ b/src/mongocxx/test_util/mock.hh @@ -119,8 +119,7 @@ class mock { } private: - instance(mock* parent) : _parent(parent) { - } + instance(mock* parent) : _parent(parent) {} mock* _parent; std::stack _callbacks; @@ -128,8 +127,7 @@ class mock { friend class instance; - mock(underlying_ptr func) : _func(std::move(func)) { - } + mock(underlying_ptr func) : _func(std::move(func)) {} mock(mock&&) = delete; mock(const mock&) = delete; mock& operator=(const mock&) = delete; diff --git a/src/mongocxx/write_concern.cpp b/src/mongocxx/write_concern.cpp index cc776e9191..cdb28059d4 100644 --- a/src/mongocxx/write_concern.cpp +++ b/src/mongocxx/write_concern.cpp @@ -32,8 +32,7 @@ namespace mongocxx { MONGOCXX_INLINE_NAMESPACE_BEGIN -write_concern::write_concern() : _impl{stdx::make_unique(libmongoc::write_concern_new())} { -} +write_concern::write_concern() : _impl{stdx::make_unique(libmongoc::write_concern_new())} {} write_concern::write_concern(std::unique_ptr&& implementation) { _impl.reset(implementation.release()); @@ -43,8 +42,7 @@ write_concern::write_concern(write_concern&&) noexcept = default; write_concern& write_concern::operator=(write_concern&&) noexcept = default; write_concern::write_concern(const write_concern& other) - : _impl(stdx::make_unique(libmongoc::write_concern_copy(other._impl->write_concern_t))) { -} + : _impl(stdx::make_unique(libmongoc::write_concern_copy(other._impl->write_concern_t))) {} write_concern& write_concern::operator=(const write_concern& other) { _impl.reset(stdx::make_unique(libmongoc::write_concern_copy(other._impl->write_concern_t)) @@ -116,7 +114,8 @@ stdx::optional write_concern::nodes() const { stdx::optional write_concern::acknowledge_level() const { stdx::optional ack_level; std::int32_t w = libmongoc::write_concern_get_w(_impl->write_concern_t); - if (w >= 1) return stdx::nullopt; + if (w >= 1) + return stdx::nullopt; switch (w) { case MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED: return write_concern::level::k_unacknowledged;