aboutsummaryrefslogtreecommitdiff
path: root/src/SongFilter.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-29 19:27:03 +0200
committerMax Kellermann <max@duempel.org>2012-08-29 20:19:02 +0200
commit333d226ed0044cf6a6387e03805be2d7f6dac6f2 (patch)
tree7acb6fc795fcd2bb8aa75c16172de1ff7a761e8f /src/SongFilter.hxx
parent04a9dec9525a58d077da71a84655cb45b7838520 (diff)
SongFilter: convert to a C++ class
Diffstat (limited to 'src/SongFilter.hxx')
-rw-r--r--src/SongFilter.hxx88
1 files changed, 68 insertions, 20 deletions
diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index 38c1dae6..a3068a97 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -22,15 +22,82 @@
#include "gcc.h"
+#include <list>
+
#include <stdint.h>
#include <stdbool.h>
#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<Item> 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