1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 18:53:09 +02:00

Store Menu's Monitors in unique_ptrs

This results in a small code reduction and some ease of mind.
This commit is contained in:
Maarten ter Huurne 2014-08-15 13:56:20 +02:00
parent 7134eb3778
commit d66ca947c4
2 changed files with 3 additions and 10 deletions

View File

@ -106,11 +106,6 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
Menu::~Menu() { Menu::~Menu() {
freeLinks(); freeLinks();
#ifdef ENABLE_INOTIFY
for (auto it : monitors)
delete it;
#endif
} }
void Menu::readSections(std::string parentDir) 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()); DEBUG("Opening packages from directory: %s\n", path.c_str());
readPackages(path); readPackages(path);
#ifdef ENABLE_INOTIFY #ifdef ENABLE_INOTIFY
monitors.push_back(new Monitor(path.c_str())); monitors.emplace_back(new Monitor(path.c_str()));
#endif #endif
} }
@ -789,10 +784,8 @@ void Menu::removePackageLink(std::string path)
} }
/* Remove registered monitors */ /* Remove registered monitors */
for (vector<Monitor *>::iterator it = monitors.begin(); for (auto it = monitors.begin(); it < monitors.end(); ++it) {
it < monitors.end(); it++) {
if ((*it)->getPath().compare(0, path.size(), path) == 0) { if ((*it)->getPath().compare(0, path.size(), path) == 0) {
delete (*it);
monitors.erase(it); monitors.erase(it);
} }
} }

View File

@ -83,7 +83,7 @@ private:
// Load all the .opk packages of the given directory // Load all the .opk packages of the given directory
void readPackages(std::string parentDir); void readPackages(std::string parentDir);
#ifdef ENABLE_INOTIFY #ifdef ENABLE_INOTIFY
std::vector<Monitor *> monitors; std::vector<std::unique_ptr<Monitor>> monitors;
#endif #endif
#endif #endif