From 5263f6880c4a7218c3d38ce9895c659f3dffd56e Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 31 Oct 2021 16:59:06 +0400 Subject: [PATCH] Internally Book supports multiple illustrations --- include/book.h | 4 +++- src/book.cpp | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/book.h b/include/book.h index d53de75d4..0f21bc481 100644 --- a/include/book.h +++ b/include/book.h @@ -21,6 +21,8 @@ #define KIWIX_BOOK_H #include +#include +#include namespace pugi { class xml_node; @@ -139,7 +141,7 @@ class Book uint64_t m_mediaCount = 0; bool m_readOnly = false; uint64_t m_size = 0; - Illustration m_illustration; + std::vector> m_illustrations; }; } diff --git a/src/book.cpp b/src/book.cpp index eccae35fc..faee20dfe 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -40,7 +40,10 @@ Book::Book() : m_pathValid(false), m_readOnly(false) { + const auto illustration = std::make_shared(); + m_illustrations.assign(1, illustration); } + /* Destructor */ Book::~Book() { @@ -72,7 +75,10 @@ bool Book::update(const kiwix::Book& other) m_articleCount = other.m_articleCount; m_mediaCount = other.m_mediaCount; m_size = other.m_size; - m_illustration = other.m_illustration; + m_illustrations.clear(); + for ( const auto& ill : other.m_illustrations ) { + m_illustrations.push_back(std::make_shared(*ill)); + } m_downloadId = other.m_downloadId; @@ -220,12 +226,14 @@ void Book::setPath(const std::string& path) const Book::Illustration& Book::getDefaultIllustration() const { - return m_illustration; + assert(m_illustrations.size() == 1); + return *m_illustrations.front(); } Book::Illustration& Book::getMutableDefaultIllustration() { - return m_illustration; + const Book* const const_this = this; + return const_cast(const_this->getDefaultIllustration()); } const std::string& Book::Illustration::getData() const