From b259afa408e3adb209ec6b2115200e491f9dddce Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 17 Apr 2021 00:32:04 +0400 Subject: [PATCH] Library::getBooksCategories() Note: no unit test added --- include/library.h | 9 ++++++++- src/library.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/library.h b/include/library.h index f358e6746..95d22e4bd 100644 --- a/include/library.h +++ b/include/library.h @@ -233,12 +233,19 @@ class Library unsigned int getBookCount(const bool localBooks, const bool remoteBooks) const; /** - * Get all langagues of the books in the library. + * Get all languagues of the books in the library. * * @return A list of languages. */ std::vector getBooksLanguages() const; + /** + * Get all categories of the books in the library. + * + * @return A list of categories. + */ + std::vector getBooksCategories() const; + /** * Get all book creators of the books in the library. * diff --git a/src/library.cpp b/src/library.cpp index d8307c9ae..1147282df 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -201,6 +201,21 @@ std::vector Library::getBooksLanguages() const return booksLanguages; } +std::vector Library::getBooksCategories() const +{ + std::set categories; + + for (const auto& pair: m_books) { + const auto& book = pair.second; + const auto& c = book.getCategory(); + if ( !c.empty() ) { + categories.insert(c); + } + } + + return std::vector(categories.begin(), categories.end()); +} + std::vector Library::getBooksCreators() const { std::vector booksCreators;