From ce8fff0b427865a41ad682cc172d9a38cad1833b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 8 Aug 2019 15:52:19 +0200 Subject: [PATCH] Make the library create the reader. --- include/library.h | 3 +++ src/library.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/library.h b/include/library.h index 7703ff1f6..5ed1d5cbc 100644 --- a/include/library.h +++ b/include/library.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "book.h" #include "bookmark.h" @@ -110,6 +111,7 @@ class Filter { class Library { std::map m_books; + std::map> m_readers; std::vector m_bookmarks; public: @@ -145,6 +147,7 @@ class Library bool removeBookmark(const std::string& zimId, const std::string& url); Book& getBookById(const std::string& id); + std::shared_ptr getReaderById(const std::string& id); /** * Remove a book from the library. diff --git a/src/library.cpp b/src/library.cpp index 524b24b83..6b2a1939d 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -19,6 +19,7 @@ #include "library.h" #include "book.h" +#include "reader.h" #include "libxml_dumper.h" #include "tools/base64.h" @@ -32,6 +33,7 @@ namespace kiwix { + /* Constructor */ Library::Library() { @@ -83,6 +85,20 @@ Book& Library::getBookById(const std::string& id) return m_books.at(id); } +std::shared_ptr Library::getReaderById(const std::string& id) +{ + try { + return m_readers.at(id); + } catch (std::out_of_range& e) {} + + auto book = getBookById(id); + if (!book.isPathValid()) + return nullptr; + auto sptr = make_shared(book.getPath()); + m_readers[id] = sptr; + return sptr; +} + unsigned int Library::getBookCount(const bool localBooks, const bool remoteBooks) {