Manager is now safe to copy

This commit is contained in:
Veloman Yunkan 2021-11-20 20:38:39 +04:00
parent 913a368a12
commit 571e417d1e
2 changed files with 15 additions and 14 deletions

View File

@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include <memory>
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<kiwix::LibraryManipulator> manipulator;
bool readBookFromPath(const std::string& path, Book* book);
bool parseXmlDom(const pugi::xml_document& doc,

View File

@ -26,28 +26,30 @@
namespace kiwix
{
namespace
{
struct NoDelete
{
template<class T> 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,