|
20 | 20 |
|
21 | 21 | #include <mongocxx/v1/detail/prelude.hpp> |
22 | 22 |
|
| 23 | +#include <mongocxx/v1/logger-fwd.hpp> |
| 24 | + |
| 25 | +#include <mongocxx/v1/config/export.hpp> |
| 26 | + |
| 27 | +#include <memory> |
| 28 | +#include <system_error> |
| 29 | +#include <type_traits> |
| 30 | + |
23 | 31 | namespace mongocxx { |
24 | 32 | namespace v1 { |
25 | 33 |
|
@@ -50,15 +58,123 @@ namespace v1 { |
50 | 58 | /// @par Special exemptions |
51 | 59 | /// Only the following API are permitted to be used outside the lifetime of an instance object: |
52 | 60 | /// - @ref mongocxx::v1::logger |
| 61 | +/// - @ref mongocxx::v1::default_logger |
53 | 62 | /// |
54 | 63 | /// @see |
55 | 64 | /// - [Initialization and Cleanup (mongoc)](https://mongoc.org/libmongoc/current/init-cleanup.html) |
56 | 65 | /// |
57 | | -class instance {}; |
| 66 | +class instance { |
| 67 | + private: |
| 68 | + class impl; |
| 69 | + std::unique_ptr<impl> _impl; |
| 70 | + |
| 71 | + public: |
| 72 | + /// |
| 73 | + /// Cleanup the mongocxx (and mongoc) library. |
| 74 | + /// |
| 75 | + /// Calls [`mongoc_cleanup()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). |
| 76 | + /// |
| 77 | + MONGOCXX_ABI_EXPORT_CDECL() ~instance(); |
| 78 | + |
| 79 | + /// |
| 80 | + /// This class is not moveable. |
| 81 | + /// |
| 82 | + instance(instance&&) = delete; |
| 83 | + |
| 84 | + /// |
| 85 | + /// This class is not moveable. |
| 86 | + /// |
| 87 | + instance& operator=(instance&&) = delete; |
| 88 | + |
| 89 | + /// |
| 90 | + /// This class is not copyable. |
| 91 | + /// |
| 92 | + instance(instance const&) = delete; |
| 93 | + |
| 94 | + /// |
| 95 | + /// This class is not copyable. |
| 96 | + /// |
| 97 | + instance& operator=(instance const&) = delete; |
| 98 | + |
| 99 | + /// |
| 100 | + /// Initialize the mongoc library with unstructured log messages disabled. |
| 101 | + /// |
| 102 | + /// Calls [`mongoc_init()`](https://mongoc.org/libmongoc/current/mongoc_init.html) after disabling unstructured |
| 103 | + /// log messages by calling `mongoc_log_set_handler(nullptr, nullptr)`. |
| 104 | + /// |
| 105 | + /// @important To use mongoc's default log message handler, construct this object with |
| 106 | + /// @ref instance(v1::default_logger tag) instead. |
| 107 | + /// |
| 108 | + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` |
| 109 | + /// object has already been created. |
| 110 | + /// |
| 111 | + /// @see |
| 112 | + /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) |
| 113 | + /// |
| 114 | + MONGOCXX_ABI_EXPORT_CDECL() instance(); |
| 115 | + |
| 116 | + /// |
| 117 | + /// Initialize the mongoc library with the custom unstructured log message handler. |
| 118 | + /// |
| 119 | + /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) after registering the custom |
| 120 | + /// unstructured log handler by calling `mongoc_log_set_handler()`. |
| 121 | + /// |
| 122 | + /// @param handler Disable unstructured logging when null. |
| 123 | + /// |
| 124 | + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` |
| 125 | + /// object has already been created. |
| 126 | + /// |
| 127 | + /// @see |
| 128 | + /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) |
| 129 | + /// |
| 130 | + explicit MONGOCXX_ABI_EXPORT_CDECL() instance(std::unique_ptr<v1::logger> handler); |
| 131 | + |
| 132 | + /// |
| 133 | + /// Initialize the mongoc library with its default unstructured log handler. |
| 134 | + /// |
| 135 | + /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) without registering any custom |
| 136 | + /// unstructured log handler. |
| 137 | + /// |
| 138 | + /// @param tag Unused: only for overload resolution. |
| 139 | + /// |
| 140 | + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` |
| 141 | + /// object has already been created. |
| 142 | + /// |
| 143 | + explicit MONGOCXX_ABI_EXPORT_CDECL() instance(v1::default_logger tag); |
| 144 | + |
| 145 | + /// |
| 146 | + /// Errors codes which may be returned by @ref mongocxx::v1::instance. |
| 147 | + /// |
| 148 | + /// @attention This feature is experimental! It is not ready for use! |
| 149 | + /// |
| 150 | + enum class errc { |
| 151 | + zero, ///< Zero. |
| 152 | + multiple_instances, ///< Cannot construct multiple instance objects in a given process. |
| 153 | + }; |
| 154 | + |
| 155 | + /// |
| 156 | + /// The error category for @ref mongocxx::v1::instance::errc. |
| 157 | + /// |
| 158 | + /// @attention This feature is experimental! It is not ready for use! |
| 159 | + /// |
| 160 | + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); |
| 161 | + |
| 162 | + /// |
| 163 | + /// Support implicit conversion to `std::error_code`. |
| 164 | + /// |
| 165 | + /// @attention This feature is experimental! It is not ready for use! |
| 166 | + /// |
| 167 | + friend std::error_code make_error_code(errc v) { |
| 168 | + return {static_cast<int>(v), error_category()}; |
| 169 | + } |
| 170 | +}; |
58 | 171 |
|
59 | 172 | } // namespace v1 |
60 | 173 | } // namespace mongocxx |
61 | 174 |
|
| 175 | +template <> |
| 176 | +struct std::is_error_code_enum<mongocxx::v1::instance::errc> : true_type {}; |
| 177 | + |
62 | 178 | #include <mongocxx/v1/detail/postlude.hpp> |
63 | 179 |
|
64 | 180 | /// |
|
0 commit comments