-
Notifications
You must be signed in to change notification settings - Fork 547
CXX-3320 migrate instance and logger to mongocxx::v1 #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
efb65cb
2892b35
0370746
4508456
40218af
3483624
75d5e9e
cc5339f
ba058a4
91b3d62
20b931c
df7bf53
f24f3b6
0be7784
f2ecef1
d2de21a
bf715d7
5160285
3d276c8
42cac6f
33c1853
4ae0cd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,13 @@ | |||||||||||||
|
|
||||||||||||||
| #include <mongocxx/v1/detail/prelude.hpp> | ||||||||||||||
|
|
||||||||||||||
| #include <bsoncxx/v1/detail/macros.hpp> | ||||||||||||||
|
|
||||||||||||||
| #include <mongocxx/v1/config/export.hpp> | ||||||||||||||
|
|
||||||||||||||
| #include <system_error> | ||||||||||||||
| #include <type_traits> | ||||||||||||||
|
|
||||||||||||||
| namespace mongocxx { | ||||||||||||||
| namespace v1 { | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -28,14 +35,60 @@ namespace v1 { | |||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| enum class source_errc {}; | ||||||||||||||
| enum class source_errc { | ||||||||||||||
| zero, ///< Zero. | ||||||||||||||
| mongocxx, ///< From the mongocxx library. | ||||||||||||||
| mongoc, ///< From the mongoc library. | ||||||||||||||
| mongocrypt, ///< From the mongocrypt library. | ||||||||||||||
| server, ///< From the MongoDB server. | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// The error category for @ref mongocxx::v1::source_errc. | ||||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) source_error_category(); | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// Support implicit conversion to `std::error_condition`. | ||||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| inline std::error_condition make_error_condition(source_errc code) { | ||||||||||||||
| return {static_cast<int>(code), v1::source_error_category()}; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// Enumeration identifying the type (cause) of a @ref mongocxx::v1 error. | ||||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| enum class type_errc {}; | ||||||||||||||
| enum class type_errc { | ||||||||||||||
| zero, ///< Zero. | ||||||||||||||
| invalid_argument, ///< An invalid argument passed to the throwing function. | ||||||||||||||
| runtime_error, ///< An erroneous condition was detected at runtime. | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// The error category for @ref mongocxx::v1::type_errc. | ||||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) type_error_category(); | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// Support implicit conversion to `std::error_condition`. | ||||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| inline std::error_condition make_error_condition(type_errc code) { | ||||||||||||||
| return {static_cast<int>(code), v1::type_error_category()}; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| BSONCXX_PRIVATE_WARNINGS_PUSH(); | ||||||||||||||
| BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); | ||||||||||||||
| BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); | ||||||||||||||
|
|
||||||||||||||
| /// | ||||||||||||||
| /// Base class for all exceptions thrown by @ref mongocxx::v1. | ||||||||||||||
|
|
@@ -45,11 +98,33 @@ enum class type_errc {}; | |||||||||||||
| /// | ||||||||||||||
| /// @attention This feature is experimental! It is not ready for use! | ||||||||||||||
| /// | ||||||||||||||
| class exception {}; | ||||||||||||||
| class exception : public std::system_error { | ||||||||||||||
| public: | ||||||||||||||
| ~exception() override; | ||||||||||||||
|
|
||||||||||||||
| exception(exception&&) noexcept = default; | ||||||||||||||
| exception& operator=(exception&&) noexcept = default; | ||||||||||||||
| exception(exception const&) = default; | ||||||||||||||
| exception& operator=(exception const&) = default; | ||||||||||||||
|
|
||||||||||||||
| using std::system_error::system_error; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| BSONCXX_PRIVATE_WARNINGS_POP(); | ||||||||||||||
|
|
||||||||||||||
| } // namespace v1 | ||||||||||||||
| } // namespace mongocxx | ||||||||||||||
|
|
||||||||||||||
| namespace std { | ||||||||||||||
|
|
||||||||||||||
| template <> | ||||||||||||||
| struct is_error_condition_enum<mongocxx::v1::source_errc> : true_type {}; | ||||||||||||||
|
|
||||||||||||||
| template <> | ||||||||||||||
| struct is_error_condition_enum<mongocxx::v1::type_errc> : true_type {}; | ||||||||||||||
|
|
||||||||||||||
| } // namespace std | ||||||||||||||
|
||||||||||||||
| # https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html | |
| # https://gcc.gnu.org/projects/cxx-status.html | |
| # https://gcc.gnu.org/releases.html | |
| if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.1") | |
| message(FATAL_ERROR "GCC 8.1 or newer is required") | |
| endif() |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,14 @@ | |||||
|
|
||||||
| #include <mongocxx/v1/detail/prelude.hpp> | ||||||
|
|
||||||
| #include <mongocxx/v1/logger-fwd.hpp> | ||||||
|
|
||||||
| #include <mongocxx/v1/config/export.hpp> | ||||||
|
|
||||||
| #include <memory> | ||||||
| #include <system_error> | ||||||
| #include <type_traits> | ||||||
|
|
||||||
| namespace mongocxx { | ||||||
| namespace v1 { | ||||||
|
|
||||||
|
|
@@ -50,15 +58,135 @@ namespace v1 { | |||||
| /// @par Special exemptions | ||||||
| /// Only the following API are permitted to be used outside the lifetime of an instance object: | ||||||
| /// - @ref mongocxx::v1::logger | ||||||
| /// - @ref mongocxx::v1::default_logger | ||||||
| /// | ||||||
| /// @see | ||||||
| /// - [Initialization and Cleanup (mongoc)](https://mongoc.org/libmongoc/current/init-cleanup.html) | ||||||
| /// | ||||||
| class instance {}; | ||||||
| class instance { | ||||||
| private: | ||||||
| class impl; | ||||||
| std::unique_ptr<impl> _impl; | ||||||
|
|
||||||
| public: | ||||||
| /// | ||||||
| /// Cleanup the mongocxx (and mongoc) library. | ||||||
| /// | ||||||
| /// Calls [`mongoc_init()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). | ||||||
|
||||||
| /// Calls [`mongoc_init()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). | |
| /// Calls [`mongoc_cleanup()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative breaking change: instance is made immovable as well as uncopyable. Allowing instance to be moved-from does not seem to be well-motivated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated documentation to clarify that this all applies to "unstructured log handling" to leave open the design space for "structured log handling" support by the C++ Driver.
Documentation also increased references to specific mongoc API to clarify behavior + defer much of the behavioral documentation to mongoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
zero, or something likeokay? Alternatively: setmongocxx = 1, give theenuma base type likeint, and then havesource_errc{}as the stand-in forzero, which is the non-error syntax forstd::errc.(I don't feel strongly about any of the above options, just something to consider.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reason for including the
zeroenumerator was twofold:= 1in the otherwise=-less list of enumerators (an inconsistency).zerocase in switch cases via-Wswitch/-Wswitch-enum.I opted for
zeroinstead ofokayto avoid implying anything beyond a description of the value itself, since "not zero" does not necessarily imply "not okay" or "not valid" given certain error code schemes (i.e. "HTTP status code 200").The default underlying type for a scoped enumeration is
int, so there is no need for explicit: intgivenenum class E.