Internally Book supports multiple illustrations

This commit is contained in:
Veloman Yunkan 2021-10-31 16:59:06 +04:00
parent c129952605
commit 5263f6880c
2 changed files with 14 additions and 4 deletions

View File

@ -21,6 +21,8 @@
#define KIWIX_BOOK_H
#include <string>
#include <vector>
#include <memory>
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<std::shared_ptr<Illustration>> m_illustrations;
};
}

View File

@ -40,7 +40,10 @@ Book::Book() :
m_pathValid(false),
m_readOnly(false)
{
const auto illustration = std::make_shared<Illustration>();
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<Illustration>(*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<Illustration&>(const_this->getDefaultIllustration());
}
const std::string& Book::Illustration::getData() const