From eb2a83db2460910e25c1222100a25787ab1ad39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Wojdy=C5=82a?= Date: Fri, 3 Dec 2021 16:45:00 +0100 Subject: [PATCH 1/2] Add register_progress_callback method to archive class --- zip.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zip.hpp b/zip.hpp index bbb92ca..831523b 100644 --- a/zip.hpp +++ b/zip.hpp @@ -121,6 +121,10 @@ using uint64_t = zip_uint64_t; */ using source = std::function; +using zip_progress_callback = void (*)(struct zip*, double, void*); + +using cleanup_callback = void (*)(void*); + /** * \brief File for reading. */ @@ -980,6 +984,15 @@ class archive { return ret; } + + void register_progress_callback(zip_progress_callback progress, + double precision, + cleanup_callback cleanup, + void* data) + { + zip_register_progress_callback_with_state( + handle_.get(), precision, progress, cleanup, data); + } }; } // !libzip From 0d7445a0bb8a4fa3cc86a2ac6528f6fdbe63bed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Wojdy=C5=82a?= Date: Mon, 6 Dec 2021 14:23:53 +0100 Subject: [PATCH 2/2] register_progress_callback rewritten in modern c++ style --- zip.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/zip.hpp b/zip.hpp index 831523b..029b69f 100644 --- a/zip.hpp +++ b/zip.hpp @@ -121,9 +121,7 @@ using uint64_t = zip_uint64_t; */ using source = std::function; -using zip_progress_callback = void (*)(struct zip*, double, void*); - -using cleanup_callback = void (*)(void*); +using zip_progress_callback = std::function; /** * \brief File for reading. @@ -985,13 +983,14 @@ class archive { return ret; } - void register_progress_callback(zip_progress_callback progress, - double precision, - cleanup_callback cleanup, - void* data) + void register_progress_callback(zip_progress_callback callback, double precision) { zip_register_progress_callback_with_state( - handle_.get(), precision, progress, cleanup, data); + handle_.get(), + precision, + [](zip*, double p, void* data) { (*static_cast(data))(p); }, + [](void* data) { delete static_cast(data); }, + new zip_progress_callback{std::move(callback)}); } };