From d66ca947c45255dab207efecce265bacb3a020d4 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 15 Aug 2014 13:56:20 +0200 Subject: [PATCH] Store Menu's Monitors in unique_ptrs This results in a small code reduction and some ease of mind. --- src/menu.cpp | 11 ++--------- src/menu.h | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 6822546..7072633 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -106,11 +106,6 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts) Menu::~Menu() { freeLinks(); - -#ifdef ENABLE_INOTIFY - for (auto it : monitors) - delete it; -#endif } void Menu::readSections(std::string parentDir) @@ -659,7 +654,7 @@ void Menu::openPackagesFromDir(std::string path) DEBUG("Opening packages from directory: %s\n", path.c_str()); readPackages(path); #ifdef ENABLE_INOTIFY - monitors.push_back(new Monitor(path.c_str())); + monitors.emplace_back(new Monitor(path.c_str())); #endif } @@ -789,10 +784,8 @@ void Menu::removePackageLink(std::string path) } /* Remove registered monitors */ - for (vector::iterator it = monitors.begin(); - it < monitors.end(); it++) { + for (auto it = monitors.begin(); it < monitors.end(); ++it) { if ((*it)->getPath().compare(0, path.size(), path) == 0) { - delete (*it); monitors.erase(it); } } diff --git a/src/menu.h b/src/menu.h index c668cbc..934e427 100644 --- a/src/menu.h +++ b/src/menu.h @@ -83,7 +83,7 @@ private: // Load all the .opk packages of the given directory void readPackages(std::string parentDir); #ifdef ENABLE_INOTIFY - std::vector monitors; + std::vector> monitors; #endif #endif