/* * Copyright 2011 Emmanuel Engelhart * * 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 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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 Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ #ifndef KIWIX_LIBRARY_H #define KIWIX_LIBRARY_H #include #include #include #define KIWIX_LIBRARY_VERSION "20110515" namespace kiwix { class Book; class OPDSDumper; /** * A Library store several books. */ class Library { std::map books; public: Library(); ~Library(); std::string version; /** * Add a book to the library. * * If a book already exist in the library with the same id, update * the existing book instead of adding a new one. * * @param book The book to add. * @return True if the book has been added. * False if a book has been updated. */ bool addBook(const Book& book); Book& getBookById(const std::string& id); /** * Remove a book from the library. * * @param id the id of the book to remove. * @return True if the book were in the lirbrary and has been removed. */ bool removeBookById(const std::string& id); /** * Write the library to a file. * * @param path the path of the file to write to. * @return True if the library has been correctly save. */ bool writeToFile(const std::string& path); /** * Get the number of book in the library. * * @param localBooks If we must count local books (books with a path). * @param remoteBooks If we must count remote books (books with an url) * @return The number of books. */ unsigned int getBookCount(const bool localBooks, const bool remoteBooks); /** * Filter the library and generate a new one with the keep elements. * * @param search List only books with search in the title or description. * @return A `Library`. */ Library filter(const std::string& search); /** * Get all langagues of the books in the library. * * @return A list of languages. */ std::vector getBooksLanguages(); /** * Get all book creators of the books in the library. * * @return A list of book creators. */ std::vector getBooksCreators(); /** * Get all book publishers of the books in the library. * * @return A list of book publishers. */ std::vector getBooksPublishers(); /** * Get all book ids of the books in the library. * * @return A list of book ids. */ std::vector getBooksIds(); friend class OPDSDumper; }; } #endif