From 333d226ed0044cf6a6387e03805be2d7f6dac6f2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 Aug 2012 19:27:03 +0200 Subject: SongFilter: convert to a C++ class --- src/SongFilter.hxx | 88 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 20 deletions(-) (limited to 'src/SongFilter.hxx') diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx index 38c1dae67..a3068a970 100644 --- a/src/SongFilter.hxx +++ b/src/SongFilter.hxx @@ -22,15 +22,82 @@ #include "gcc.h" +#include + #include #include #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10 #define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20 -struct locate_item_list; +struct tag; +struct tag_item; struct song; +class SongFilter { + class Item { + uint8_t tag; + + bool fold_case; + + char *value; + + public: + gcc_nonnull(3) + Item(unsigned tag, const char *value, bool fold_case=false); + + Item(const Item &other) = delete; + + Item(Item &&other) + :tag(other.tag), fold_case(other.fold_case), + value(other.value) { + other.value = nullptr; + } + + ~Item(); + + Item &operator=(const Item &other) = delete; + + unsigned GetTag() const { + return tag; + } + + gcc_pure gcc_nonnull(2) + bool StringMatch(const char *s) const; + + gcc_pure + bool Match(const tag_item &tag_item) const; + + gcc_pure + bool Match(const struct tag &tag) const; + + gcc_pure + bool Match(const song &song) const; + }; + + std::list items; + +public: + SongFilter() = default; + + gcc_nonnull(3) + SongFilter(unsigned tag, const char *value, bool fold_case=false); + + ~SongFilter(); + + gcc_nonnull(2,3) + bool Parse(const char *tag, const char *value, bool fold_case=false); + + gcc_nonnull(3) + bool Parse(unsigned argc, char *argv[], bool fold_case=false); + + gcc_pure + bool Match(const tag &tag) const; + + gcc_pure + bool Match(const song &song) const; +}; + /** * @return #TAG_NUM_OF_ITEM_TYPES on error */ @@ -38,23 +105,4 @@ gcc_pure unsigned locate_parse_type(const char *str); -gcc_malloc -struct locate_item_list * -locate_item_list_new_single(unsigned tag, const char *needle); - -/* return number of items or -1 on error */ -gcc_nonnull(1) -struct locate_item_list * -locate_item_list_parse(char *argv[], unsigned argc, bool fold_case); - -gcc_nonnull(1) -void -locate_item_list_free(struct locate_item_list *list); - -gcc_pure -gcc_nonnull(1,2) -bool -locate_list_song_match(const struct song *song, - const struct locate_item_list *criteria); - #endif -- cgit v1.2.3