Be able to filter the books by name.

This commit is contained in:
Matthieu Gautier 2020-01-30 11:14:35 +01:00
parent d14ba0c2e8
commit f560a1f815
2 changed files with 11 additions and 0 deletions

View File

@ -57,6 +57,7 @@ class Filter {
std::string _creator;
size_t _maxSize;
std::string _query;
std::string _name;
public:
Filter();
@ -100,6 +101,7 @@ class Filter {
Filter& creator(std::string creator);
Filter& maxSize(size_t size);
Filter& query(std::string query);
Filter& name(std::string name);
bool accept(const Book& book) const;
};

View File

@ -378,6 +378,7 @@ enum filterTypes {
_CREATOR = FLAG(10),
MAXSIZE = FLAG(11),
QUERY = FLAG(12),
NAME = FLAG(13),
};
Filter& Filter::local(bool accept)
@ -465,6 +466,13 @@ Filter& Filter::query(std::string query)
return *this;
}
Filter& Filter::name(std::string name)
{
_name = name;
activeFilters |= NAME;
return *this;
}
#define ACTIVE(X) (activeFilters & (X))
#define FILTER(TAG, TEST) if (ACTIVE(TAG) && !(TEST)) { return false; }
bool Filter::accept(const Book& book) const
@ -485,6 +493,7 @@ bool Filter::accept(const Book& book) const
FILTER(LANG, book.getLanguage() == _lang)
FILTER(_PUBLISHER, book.getPublisher() == _publisher)
FILTER(_CREATOR, book.getCreator() == _creator)
FILTER(NAME, book.getName() == _name)
if (ACTIVE(ACCEPTTAGS)) {
if (!_acceptTags.empty()) {