From 17b259df9cb6b28779d4881b2b6c805ee2e48eea Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 7 Jun 2024 23:30:05 +0900 Subject: Rename to tde-ebook-reader Signed-off-by: Michele Calgaro --- reader/src/network/NetworkBookCollection.cpp | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 reader/src/network/NetworkBookCollection.cpp (limited to 'reader/src/network/NetworkBookCollection.cpp') diff --git a/reader/src/network/NetworkBookCollection.cpp b/reader/src/network/NetworkBookCollection.cpp new file mode 100644 index 0000000..155d702 --- /dev/null +++ b/reader/src/network/NetworkBookCollection.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus + * + * 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 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. + */ + +#include + +#include + +#include "NetworkBookCollection.h" + + +NetworkBookCollection::NetworkBookCollection() { + myAuthorComparator = new NetworkAuthorComparator(myAuthorRates); +} + +void NetworkBookCollection::clear() { + myBookList.clear(); + myAuthorRates.clear(); + myAuthorBooksMap.reset(); +} + +void NetworkBookCollection::addBook(shared_ptr bookPtr) { + if (bookPtr.isNull() || bookPtr->typeId() != NetworkBookItem::TYPE_ID) { + return; + } + myAuthorBooksMap.reset(); + + NetworkItem::List::iterator it = std::upper_bound(myBookList.begin(), myBookList.end(), bookPtr, NetworkBookItemComparator()); + myBookList.insert(it, bookPtr); + + NetworkBookItem &book = (NetworkBookItem &) *bookPtr; + + for (std::vector::const_iterator jt = book.Authors.begin(); jt != book.Authors.end(); ++jt) { + const NetworkBookItem::AuthorData &author = *jt; + std::map::iterator kt = myAuthorRates.find(author); + if (kt == myAuthorRates.end()) { + myAuthorRates[author] = book.Index; + } else if (kt->second > book.Index) { + kt->second = book.Index; + } + } +} + +const NetworkAuthorBooksMap &NetworkBookCollection::authorBooksMap() { + if (myAuthorBooksMap.isNull()) { + myAuthorBooksMap = new NetworkAuthorBooksMap(*myAuthorComparator); + NetworkAuthorBooksMap &bookMap = *myAuthorBooksMap; + for (NetworkItem::List::const_iterator it = myBookList.begin(); it != myBookList.end(); ++it) { + NetworkBookItem &book = (NetworkBookItem &) **it; + for (std::vector::const_iterator jt = book.Authors.begin(); jt != book.Authors.end(); ++jt) { + bookMap[*jt].push_back(*it); + } + } + } + return *myAuthorBooksMap; +} -- cgit v1.2.3