.. _program_listing_file_include_zim_writer_contentProvider.h: Program Listing for File contentProvider.h ========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/zim/writer/contentProvider.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (C) 2020 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_CONTENTPROVIDER_H #define ZIM_WRITER_CONTENTPROVIDER_H #include #include #include #include namespace zim { #ifdef _WIN32 #define DEFAULTFD zim::windows::FD namespace windows { #else #define DEFAULTFD zim::unix::FD namespace unix { #endif class FD; } namespace writer { class LIBZIM_API ContentProvider { public: virtual ~ContentProvider() = default; virtual zim::size_type getSize() const = 0; virtual Blob feed() = 0; }; class LIBZIM_API StringProvider : public ContentProvider { public: explicit StringProvider(const std::string& content) : content(content), feeded(false) {} zim::size_type getSize() const { return content.size(); } Blob feed(); protected: std::string content; bool feeded; }; class LIBZIM_API SharedStringProvider : public ContentProvider { public: explicit SharedStringProvider(std::shared_ptr content) : content(content), feeded(false) {} zim::size_type getSize() const { return content->size(); } Blob feed(); protected: std::shared_ptr content; bool feeded; }; class LIBZIM_API FileProvider : public ContentProvider { public: explicit FileProvider(const std::string& filepath); ~FileProvider(); zim::size_type getSize() const { return size; } Blob feed(); protected: std::string filepath; zim::size_type size; private: std::unique_ptr buffer; std::unique_ptr fd; zim::offset_type offset; }; } } #undef DEFAULTFD #endif // ZIM_WRITER_CONTENTPROVIDER_H