.. _program_listing_file_include_zim_writer_item.h: Program Listing for File item.h =============================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/zim/writer/item.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (C) 2020-2021 Matthieu Gautier * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef ZIM_WRITER_ITEM_H #define ZIM_WRITER_ITEM_H #include #include #include #include #include #include namespace zim { namespace writer { enum HintKeys { COMPRESS, FRONT_ARTICLE, }; using Hints = std::map; class ContentProvider; class LIBZIM_API IndexData { public: using GeoPosition = std::tuple; virtual ~IndexData() = default; virtual bool hasIndexData() const = 0; virtual std::string getTitle() const = 0; virtual std::string getContent() const = 0; virtual std::string getKeywords() const = 0; virtual uint32_t getWordCount() const = 0; virtual GeoPosition getGeoPosition() const = 0; }; class LIBZIM_API Item { public: virtual std::string getPath() const = 0; virtual std::string getTitle() const = 0; virtual std::string getMimeType() const = 0; virtual std::unique_ptr getContentProvider() const = 0; virtual std::shared_ptr getIndexData() const; virtual Hints getHints() const; Hints getAmendedHints() const; virtual ~Item() = default; }; class LIBZIM_API BasicItem : public Item { public: BasicItem(const std::string& path, const std::string& mimetype, const std::string& title, Hints hints) : path(path), mimetype(mimetype), title(title), hints(hints) {} std::string getPath() const { return path; } std::string getTitle() const { return title; } std::string getMimeType() const { return mimetype; } Hints getHints() const { return hints; } protected: std::string path; std::string mimetype; std::string title; Hints hints; }; class LIBZIM_API StringItem : public BasicItem, public std::enable_shared_from_this { public: template static std::shared_ptr create(Ts&&... params) { return std::shared_ptr(new StringItem(std::forward(params)...)); } std::unique_ptr getContentProvider() const; protected: std::string content; private: StringItem(const std::string& path, const std::string& mimetype, const std::string& title, Hints hints, const std::string& content) : BasicItem(path, mimetype, title, hints), content(content) {} }; class LIBZIM_API FileItem : public BasicItem { public: FileItem(const std::string& path, const std::string& mimetype, const std::string& title, Hints hints, const std::string& filepath) : BasicItem(path, mimetype, title, hints), filepath(filepath) {} std::unique_ptr getContentProvider() const; protected: std::string filepath; }; } } #endif // ZIM_WRITER_ITEM_H