From 488d27204e35c9adb1b01e9fab6a9490c8beaa67 Mon Sep 17 00:00:00 2001 From: Enrico Maria Crisostomo Date: Sat, 28 Dec 2024 00:15:19 +0000 Subject: [PATCH] Refactor inotify_monitor to use std::unique_ptr for implementation management and override destructor and run method --- libfswatch/src/libfswatch/c++/inotify_monitor.cpp | 4 +--- libfswatch/src/libfswatch/c++/inotify_monitor.hpp | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libfswatch/src/libfswatch/c++/inotify_monitor.cpp b/libfswatch/src/libfswatch/c++/inotify_monitor.cpp index 3626e622..9c4a514c 100644 --- a/libfswatch/src/libfswatch/c++/inotify_monitor.cpp +++ b/libfswatch/src/libfswatch/c++/inotify_monitor.cpp @@ -73,7 +73,7 @@ namespace fsw FSW_EVENT_CALLBACK *callback, void *context) : monitor(paths_to_monitor, callback, context), - impl(new inotify_monitor_impl()) + impl(std::make_unique()) { impl->inotify_monitor_handle = inotify_init(); @@ -104,8 +104,6 @@ namespace fsw { close(impl->inotify_monitor_handle); } - - delete impl; } bool inotify_monitor::add_watch(const std::string& path) diff --git a/libfswatch/src/libfswatch/c++/inotify_monitor.hpp b/libfswatch/src/libfswatch/c++/inotify_monitor.hpp index 88be84c3..d8096c84 100644 --- a/libfswatch/src/libfswatch/c++/inotify_monitor.hpp +++ b/libfswatch/src/libfswatch/c++/inotify_monitor.hpp @@ -31,6 +31,7 @@ # include # include # include +# include namespace fsw { @@ -59,7 +60,7 @@ namespace fsw /** * @brief Destroys an instance of this class. */ - virtual ~inotify_monitor(); + ~inotify_monitor() override; protected: /** @@ -69,7 +70,7 @@ namespace fsw * * @see stop() */ - void run(); + void run() override; private: inotify_monitor(const inotify_monitor& orig) = delete; @@ -85,7 +86,7 @@ namespace fsw void process_pending_events(); void remove_watch(int fd); - inotify_monitor_impl *impl; + std::unique_ptr impl; }; }