diff --git a/src/actions.cpp b/src/actions.cpp index 6d1632b7be..ca8966e181 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -169,43 +169,35 @@ namespace Action { void TaskFactory::cleanup() { - for (auto&& i : registry_) { - delete i.second; - } + registry_.clear(); } void TaskFactory::registerTask(TaskType type, Task::UniquePtr task) { - auto i = registry_.find(type); - if (i != registry_.end()) { - delete i->second; - } - registry_[type] = task.release(); + registry_[type] = std::move(task); } TaskFactory::TaskFactory() { - // Register a prototype of each known task - registerTask(adjust, std::make_unique()); - registerTask(print, std::make_unique()); - registerTask(rename, std::make_unique()); - registerTask(erase, std::make_unique()); - registerTask(extract, std::make_unique()); - registerTask(insert, std::make_unique()); - registerTask(modify, std::make_unique()); - registerTask(fixiso, std::make_unique()); - registerTask(fixcom, std::make_unique()); - } // TaskFactory c'tor + registry_.emplace(adjust, std::make_unique()); + registry_.emplace(print, std::make_unique()); + registry_.emplace(rename, std::make_unique()); + registry_.emplace(erase, std::make_unique()); + registry_.emplace(extract, std::make_unique()); + registry_.emplace(insert, std::make_unique()); + registry_.emplace(modify, std::make_unique()); + registry_.emplace(fixiso, std::make_unique()); + registry_.emplace(fixcom, std::make_unique()); + } Task::UniquePtr TaskFactory::create(TaskType type) { auto i = registry_.find(type); - if (i != registry_.end() && i->second != 0) { - Task* t = i->second; - return t->clone(); + if (i != registry_.end() && i->second) { + return i->second->clone(); } return nullptr; - } // TaskFactory::create + } int setModeAndPrintStructure(Exiv2::PrintStructureOption option, const std::string& path,bool binary) { diff --git a/src/actions.hpp b/src/actions.hpp index 065f2044ff..4520f219a6 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -31,6 +31,7 @@ // ***************************************************************************** // included header files #include "exiv2app.hpp" +#include // ***************************************************************************** // class declarations @@ -141,7 +142,7 @@ namespace Action { TaskFactory(); //! List of task types and corresponding prototypes. - std::map registry_; + std::unordered_map registry_; }; //! %Print the Exif (or other metadata) of a file to stdout