Kelson has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/295460 )
Change subject: Move zim::writer::ArticleSource::getData() to
zim::writer::Article::getData().
......................................................................
Move zim::writer::ArticleSource::getData() to zim::writer::Article::getData().
When building a ZIM file incrementally, it makes more sense to provide
the data upfront as soon as you return the Article object from
ArticleSource::getNextArticle. This is the way that the Category
object already works.
Change-Id: I78f2a69ae3931cc43a51cdab360468e13fcc54cb
---
M zimlib/examples/createZimExample.cpp
M zimlib/include/zim/writer/articlesource.h
M zimlib/src/articlesource.cpp
M zimlib/src/zimcreator.cpp
4 files changed, 54 insertions(+), 14 deletions(-)
Approvals:
Kelson: Verified; Looks good to me, approved
diff --git a/zimlib/examples/createZimExample.cpp
b/zimlib/examples/createZimExample.cpp
index 914000c..95b8d09 100644
--- a/zimlib/examples/createZimExample.cpp
+++ b/zimlib/examples/createZimExample.cpp
@@ -40,7 +40,7 @@
virtual std::string getMimeType() const;
virtual std::string getRedirectAid() const;
- zim::Blob data()
+ virtual zim::Blob getData() const
{ return zim::Blob(&_data[0], _data.size()); }
};
@@ -96,7 +96,6 @@
explicit TestArticleSource(unsigned max = 16);
virtual const zim::writer::Article* getNextArticle();
- virtual zim::Blob getData(const std::string& aid);
};
TestArticleSource::TestArticleSource(unsigned max)
@@ -119,14 +118,6 @@
unsigned n = _next++;
return &_articles[n];
-}
-
-zim::Blob TestArticleSource::getData(const std::string& aid)
-{
- unsigned n;
- std::istringstream s(aid);
- s >> n;
- return _articles[n-1].data();
}
int main(int argc, char* argv[])
diff --git a/zimlib/include/zim/writer/articlesource.h
b/zimlib/include/zim/writer/articlesource.h
index 1fda337..94ee91b 100644
--- a/zimlib/include/zim/writer/articlesource.h
+++ b/zimlib/include/zim/writer/articlesource.h
@@ -20,16 +20,16 @@
#ifndef ZIM_WRITER_ARTICLESOURCE_H
#define ZIM_WRITER_ARTICLESOURCE_H
+#include <zim/blob.h>
#include <zim/zim.h>
#include <zim/fileheader.h>
#include <string>
namespace zim
{
- class Blob;
-
namespace writer
{
+ class ArticleSource;
class Article
{
public:
@@ -45,9 +45,26 @@
virtual bool shouldCompress() const;
virtual std::string getRedirectAid() const;
virtual std::string getParameter() const;
+ /* Idealy this method should be pure virtual,
+ * but for compatibility reasons, provide a default implementation
+ * using the old ArticleSourc::getData.
+ */
+ virtual Blob getData() const;
// returns the next category id, to which the article is assigned to
virtual std::string getNextCategory();
+
+
/************************************************************************/
+ /* For API compatibility.
+ * The default Article::getData call ArticleSource::getData.
+ * So store the source of article in article to let default API
compatible
+ * function do its job.
+ * This should be removed once every users switch to new API.
+ */
+ private:
+ mutable ArticleSource* __source;
+ friend class ZimCreator;
+
/************************************************************************/
};
class Category
@@ -63,7 +80,6 @@
public:
virtual void setFilename(const std::string& fname) { }
virtual const Article* getNextArticle() = 0;
- virtual Blob getData(const std::string& aid) = 0;
virtual Uuid getUuid();
virtual std::string getMainPage();
virtual std::string getLayoutPage();
@@ -73,6 +89,16 @@
// ids. Using this list, the writer fetches the category data using
// this method.
virtual Category* getCategory(const std::string& cid);
+
+
/**********************************************************************/
+ /* For API compatibility.
+ * The default Article::getData call ArticleSource::getData.
+ * So keep the getData. Do not set it pure virtual cause we want new
+ * code to not use it.
+ * This should be removed once every users switch to new API.
+ */
+ virtual Blob getData(const std::string& aid) { throw "This should not
be called"; };
+
/**********************************************************************/
};
}
diff --git a/zimlib/src/articlesource.cpp b/zimlib/src/articlesource.cpp
index 4d1ec91..cc72ae2 100644
--- a/zimlib/src/articlesource.cpp
+++ b/zimlib/src/articlesource.cpp
@@ -17,6 +17,7 @@
*
*/
+#include <zim/blob.h>
#include <zim/writer/articlesource.h>
namespace zim
@@ -68,6 +69,19 @@
return std::string();
}
+
/**************************************************************************/
+ /* For API compatibility.
+ * The default Article::getData call ArticleSource::getData.
+ * This should be removed once every users switch to new API.
+ */
+ Blob Article::getData() const
+ {
+ std::cerr << "DEPRECATED WARNING : Use of ArticleSource::getData is
deprecated." << std::endl;
+ std::cerr << " You should override Article::getData
directly." << std::endl;
+ return __source->getData(getAid());
+ }
+
/**************************************************************************/
+
Uuid ArticleSource::getUuid()
{
return Uuid::generate();
diff --git a/zimlib/src/zimcreator.cpp b/zimlib/src/zimcreator.cpp
index ac2720b..d3bec2b 100644
--- a/zimlib/src/zimcreator.cpp
+++ b/zimlib/src/zimcreator.cpp
@@ -201,7 +201,16 @@
}
// Add blob data to compressed or uncompressed cluster.
- Blob blob = src.getData(dirent.getAid());
+
/**********************************************************************/
+ /* For API compatibility.
+ * The default Article::getData call ArticleSource::getData.
+ * So set the source of article to let default API compatible function
+ * do its job.
+ * This should be removed once every users switch to new API.
+ */
+ article->__source = &src;
+
/**********************************************************************/
+ Blob blob = article->getData();
if (blob.size() > 0)
{
isEmpty = false;
--
To view, visit https://gerrit.wikimedia.org/r/295460
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I78f2a69ae3931cc43a51cdab360468e13fcc54cb
Gerrit-PatchSet: 3
Gerrit-Project: openzim
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Kelson <[email protected]>
Gerrit-Reviewer: Mgautierfr <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits