From 446dbc9d6c4f5930da7bfbdf7c141ed9bc280922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sat, 18 Nov 2023 00:40:10 +0300 Subject: [PATCH] =?UTF-8?q?mdbx++:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20`cursor::clone()`=20(backport).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdbx.h++ | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mdbx.h++ b/mdbx.h++ index 468e8df6..9438c865 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -4252,6 +4252,7 @@ public: inline cursor &operator=(cursor &&other) noexcept; inline cursor(cursor &&other) noexcept; inline ~cursor() noexcept; + inline cursor_managed clone(void *your_context = nullptr) const; MDBX_CXX14_CONSTEXPR operator bool() const noexcept; MDBX_CXX14_CONSTEXPR operator const MDBX_cursor *() const; MDBX_CXX14_CONSTEXPR operator MDBX_cursor *(); @@ -4420,7 +4421,8 @@ class LIBMDBX_API_TYPE cursor_managed : public cursor { public: /// \brief Creates a new managed cursor with underlying object. - cursor_managed() : cursor_managed(::mdbx_cursor_create(nullptr)) { + cursor_managed(void *your_context = nullptr) + : cursor_managed(::mdbx_cursor_create(your_context)) { if (MDBX_UNLIKELY(!handle_)) MDBX_CXX20_UNLIKELY error::throw_exception(MDBX_ENOMEM); } @@ -6036,6 +6038,12 @@ inline ptrdiff_t txn::estimate_to_last(map_handle map, MDBX_CXX11_CONSTEXPR cursor::cursor(MDBX_cursor *ptr) noexcept : handle_(ptr) {} +inline cursor_managed cursor::clone(void *your_context) const { + cursor_managed clone(your_context); + error::success_or_throw(::mdbx_cursor_copy(handle_, clone.handle_)); + return clone; +} + inline cursor &cursor::operator=(cursor &&other) noexcept { handle_ = other.handle_; other.handle_ = nullptr;