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.
This commit is contained in:
Matthieu Gautier 2022-01-12 18:10:28 +01:00
parent 39732e2bcf
commit 96e0d15ab4
3 changed files with 18 additions and 8 deletions

View File

@ -47,7 +47,7 @@ class Entry
* *
* @param article a zim::Article object * @param article a zim::Article object
*/ */
Entry(zim::Entry entry); DEPRECATED Entry(zim::Entry entry) : Entry(entry, true) {};
virtual ~Entry() = default; virtual ~Entry() = default;
/** /**
@ -176,6 +176,16 @@ class Entry
private: private:
zim::Entry entry; 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;
}; };
} }

View File

@ -23,7 +23,7 @@
namespace kiwix namespace kiwix
{ {
Entry::Entry(zim::Entry entry) Entry::Entry(zim::Entry entry, bool _marker)
: entry(entry) : entry(entry)
{ {
} }
@ -53,7 +53,7 @@ Entry Entry::getRedirectEntry() const
throw NoEntry(); throw NoEntry();
} }
return entry.getRedirectEntry(); return Entry(entry.getRedirectEntry(), true);
} }
Entry Entry::getFinalEntry() const Entry Entry::getFinalEntry() const
@ -67,7 +67,7 @@ Entry Entry::getFinalEntry() const
if (final_entry.isRedirect()) { if (final_entry.isRedirect()) {
throw NoEntry(); throw NoEntry();
} }
return final_entry; return Entry(final_entry, true);
} }
} }

View File

@ -122,7 +122,7 @@ string Reader::getId() const
Entry Reader::getRandomPage() const Entry Reader::getRandomPage() const
{ {
try { try {
return zimArchive->getRandomEntry(); return Entry(zimArchive->getRandomEntry(), true);
} catch(...) { } catch(...) {
throw NoEntry(); throw NoEntry();
} }
@ -130,7 +130,7 @@ Entry Reader::getRandomPage() const
Entry Reader::getMainPage() const Entry Reader::getMainPage() const
{ {
return zimArchive->getMainEntry(); return Entry(zimArchive->getMainEntry(), true);
} }
bool Reader::getFavicon(string& content, string& mimeType) const bool Reader::getFavicon(string& content, string& mimeType) const
@ -242,7 +242,7 @@ string Reader::getScraper() const
Entry Reader::getEntryFromPath(const std::string& path) const Entry Reader::getEntryFromPath(const std::string& path) const
{ {
try { try {
return kiwix::getEntryFromPath(*zimArchive, path); return Entry(kiwix::getEntryFromPath(*zimArchive, path), true);
} catch (zim::EntryNotFound& e) { } catch (zim::EntryNotFound& e) {
throw NoEntry(); throw NoEntry();
} }
@ -256,7 +256,7 @@ Entry Reader::getEntryFromEncodedPath(const std::string& path) const
Entry Reader::getEntryFromTitle(const std::string& title) const Entry Reader::getEntryFromTitle(const std::string& title) const
{ {
try { try {
return zimArchive->getEntryByTitle(title); return Entry(zimArchive->getEntryByTitle(title), true);
} catch(zim::EntryNotFound& e) { } catch(zim::EntryNotFound& e) {
throw NoEntry(); throw NoEntry();
} }