@@ -208,23 +208,36 @@ bool Library::writeBookmarksToFile(const std::string& path) const
208
208
return writeTextFile (path, dumper.dumpLibXMLBookmark ());
209
209
}
210
210
211
- std::vector<std::string> Library::getBooksLanguages ( ) const
211
+ Library::AttributeCounts Library::getBookAttributeCounts (BookStrPropMemFn p ) const
212
212
{
213
- std::vector<std::string> booksLanguages;
214
- std::map<std::string, bool > booksLanguagesMap;
213
+ AttributeCounts propValueCounts;
215
214
216
- for (auto & pair: m_books) {
217
- auto & book = pair.second ;
218
- auto & language = book.getLanguage ();
219
- if (booksLanguagesMap.find (language) == booksLanguagesMap.end ()) {
220
- if (book.getOrigId ().empty ()) {
221
- booksLanguagesMap[language] = true ;
222
- booksLanguages.push_back (language);
223
- }
215
+ for (const auto & pair: m_books) {
216
+ const auto & book = pair.second ;
217
+ if (book.getOrigId ().empty ()) {
218
+ propValueCounts[(book.*p)()] += 1 ;
224
219
}
225
220
}
221
+ return propValueCounts;
222
+ }
223
+
224
+ std::vector<std::string> Library::getBookPropValueSet (BookStrPropMemFn p) const
225
+ {
226
+ std::vector<std::string> result;
227
+ for ( const auto & kv : getBookAttributeCounts (p) ) {
228
+ result.push_back (kv.first );
229
+ }
230
+ return result;
231
+ }
232
+
233
+ std::vector<std::string> Library::getBooksLanguages () const
234
+ {
235
+ return getBookPropValueSet (&Book::getLanguage);
236
+ }
226
237
227
- return booksLanguages;
238
+ Library::AttributeCounts Library::getBooksLanguagesWithCounts () const
239
+ {
240
+ return getBookAttributeCounts (&Book::getLanguage);
228
241
}
229
242
230
243
std::vector<std::string> Library::getBooksCategories () const
@@ -244,40 +257,12 @@ std::vector<std::string> Library::getBooksCategories() const
244
257
245
258
std::vector<std::string> Library::getBooksCreators () const
246
259
{
247
- std::vector<std::string> booksCreators;
248
- std::map<std::string, bool > booksCreatorsMap;
249
-
250
- for (auto & pair: m_books) {
251
- auto & book = pair.second ;
252
- auto & creator = book.getCreator ();
253
- if (booksCreatorsMap.find (creator) == booksCreatorsMap.end ()) {
254
- if (book.getOrigId ().empty ()) {
255
- booksCreatorsMap[creator] = true ;
256
- booksCreators.push_back (creator);
257
- }
258
- }
259
- }
260
-
261
- return booksCreators;
260
+ return getBookPropValueSet (&Book::getCreator);
262
261
}
263
262
264
263
std::vector<std::string> Library::getBooksPublishers () const
265
264
{
266
- std::vector<std::string> booksPublishers;
267
- std::map<std::string, bool > booksPublishersMap;
268
-
269
- for (auto & pair:m_books) {
270
- auto & book = pair.second ;
271
- auto & publisher = book.getPublisher ();
272
- if (booksPublishersMap.find (publisher) == booksPublishersMap.end ()) {
273
- if (book.getOrigId ().empty ()) {
274
- booksPublishersMap[publisher] = true ;
275
- booksPublishers.push_back (publisher);
276
- }
277
- }
278
- }
279
-
280
- return booksPublishers;
265
+ return getBookPropValueSet (&Book::getPublisher);
281
266
}
282
267
283
268
const std::vector<kiwix::Bookmark> Library::getBookmarks (bool onlyValidBookmarks) const
0 commit comments