From 96e0d15ab453f0b27e3790df13d0fcfb959b582b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:10:28 +0100 Subject: [PATCH] Deprecate `Entry` creation. As the `Entry` is still created by `Reader` we need a way to create a entry without raising a deprecated warning. To do so we create a second constructor with a dummy argument. This second constructor is private and is not marked as deprecated so we can use it. --- include/entry.h | 12 +++++++++++- src/entry.cpp | 6 +++--- src/reader.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/entry.h b/include/entry.h index bbddebd0e..a5b1b4746 100644 --- a/include/entry.h +++ b/include/entry.h @@ -47,7 +47,7 @@ class Entry * * @param article a zim::Article object */ - Entry(zim::Entry entry); + DEPRECATED Entry(zim::Entry entry) : Entry(entry, true) {}; virtual ~Entry() = default; /** @@ -176,6 +176,16 @@ class Entry private: zim::Entry entry; + + private: + // Entry is deprecated, so we've marked the constructor as deprecated. + // But we still need to construct the entry (in our deprecated code) + // To avoid warning because we use deprecated function, we create a second + // constructor not deprecated. The `bool marker` is unused, it sole purpose + // is to change the signature to have two different constructor. + // This one is not deprecated and we must use it in our private code. + Entry(zim::Entry entry, bool marker); + friend class Reader; }; } diff --git a/src/entry.cpp b/src/entry.cpp index 91abbe6e9..02f8640c4 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -23,7 +23,7 @@ namespace kiwix { -Entry::Entry(zim::Entry entry) +Entry::Entry(zim::Entry entry, bool _marker) : entry(entry) { } @@ -53,7 +53,7 @@ Entry Entry::getRedirectEntry() const throw NoEntry(); } - return entry.getRedirectEntry(); + return Entry(entry.getRedirectEntry(), true); } Entry Entry::getFinalEntry() const @@ -67,7 +67,7 @@ Entry Entry::getFinalEntry() const if (final_entry.isRedirect()) { throw NoEntry(); } - return final_entry; + return Entry(final_entry, true); } } diff --git a/src/reader.cpp b/src/reader.cpp index 6af7de6f7..7bcbe8707 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -122,7 +122,7 @@ string Reader::getId() const Entry Reader::getRandomPage() const { try { - return zimArchive->getRandomEntry(); + return Entry(zimArchive->getRandomEntry(), true); } catch(...) { throw NoEntry(); } @@ -130,7 +130,7 @@ Entry Reader::getRandomPage() const Entry Reader::getMainPage() const { - return zimArchive->getMainEntry(); + return Entry(zimArchive->getMainEntry(), true); } bool Reader::getFavicon(string& content, string& mimeType) const @@ -242,7 +242,7 @@ string Reader::getScraper() const Entry Reader::getEntryFromPath(const std::string& path) const { try { - return kiwix::getEntryFromPath(*zimArchive, path); + return Entry(kiwix::getEntryFromPath(*zimArchive, path), true); } catch (zim::EntryNotFound& e) { throw NoEntry(); } @@ -256,7 +256,7 @@ Entry Reader::getEntryFromEncodedPath(const std::string& path) const Entry Reader::getEntryFromTitle(const std::string& title) const { try { - return zimArchive->getEntryByTitle(title); + return Entry(zimArchive->getEntryByTitle(title), true); } catch(zim::EntryNotFound& e) { throw NoEntry(); }