diff --git a/include/manager.h b/include/manager.h index d9952a40a..af12eac02 100644 --- a/include/manager.h +++ b/include/manager.h @@ -26,6 +26,7 @@ #include #include +#include namespace pugi { class xml_document; @@ -64,7 +65,6 @@ class Manager public: explicit Manager(LibraryManipulator* manipulator); explicit Manager(Library* library); - ~Manager(); /** * Read a `library.xml` and add book in the file to the library. @@ -150,8 +150,7 @@ class Manager uint64_t m_itemsPerPage = 0; protected: - kiwix::LibraryManipulator* manipulator; - bool mustDeleteManipulator; + std::shared_ptr manipulator; bool readBookFromPath(const std::string& path, Book* book); bool parseXmlDom(const pugi::xml_document& doc, diff --git a/src/manager.cpp b/src/manager.cpp index 550842cd0..dbd094c2b 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -26,28 +26,30 @@ namespace kiwix { + +namespace +{ + +struct NoDelete +{ + template void operator()(T*) {} +}; + +} // unnamed namespace + /* Constructor */ Manager::Manager(LibraryManipulator* manipulator): writableLibraryPath(""), - manipulator(manipulator), - mustDeleteManipulator(false) + manipulator(manipulator, NoDelete()) { } Manager::Manager(Library* library) : writableLibraryPath(""), - manipulator(new DefaultLibraryManipulator(library)), - mustDeleteManipulator(true) + manipulator(new DefaultLibraryManipulator(library)) { } -/* Destructor */ -Manager::~Manager() -{ - if (mustDeleteManipulator) { - delete manipulator; - } -} bool Manager::parseXmlDom(const pugi::xml_document& doc, bool readOnly, const std::string& libraryPath,