SongFilter.hxx 2.79 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

20 21
#ifndef MPD_SONG_FILTER_HXX
#define MPD_SONG_FILTER_HXX
22

23
#include "Compiler.h"
24

25
#include <list>
26
#include <string>
27

28
#include <stdint.h>
29

30 31 32 33 34
/**
 * Limit the search to files within the given directory.
 */
#define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)

35 36 37
#define LOCATE_TAG_FILE_TYPE	TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_ANY_TYPE     TAG_NUM_OF_ITEM_TYPES+20

Max Kellermann's avatar
Max Kellermann committed
38 39
struct Tag;
struct TagItem;
40
struct Song;
41

42
class SongFilter {
43
public:
44 45 46 47 48
	class Item {
		uint8_t tag;

		bool fold_case;

49
		std::string value;
50 51 52 53 54 55

	public:
		gcc_nonnull(3)
		Item(unsigned tag, const char *value, bool fold_case=false);

		Item(const Item &other) = delete;
56
		Item(Item &&) = default;
57 58 59 60 61 62 63

		Item &operator=(const Item &other) = delete;

		unsigned GetTag() const {
			return tag;
		}

64 65 66 67
		bool GetFoldCase() const {
			return fold_case;
		}

68 69 70 71
		const std::string &GetValue() const {
			return value;
		}

72 73 74 75
		gcc_pure gcc_nonnull(2)
		bool StringMatch(const char *s) const;

		gcc_pure
Max Kellermann's avatar
Max Kellermann committed
76
		bool Match(const TagItem &tag_item) const;
77 78

		gcc_pure
Max Kellermann's avatar
Max Kellermann committed
79
		bool Match(const Tag &tag) const;
80 81

		gcc_pure
82
		bool Match(const Song &song) const;
83 84
	};

85
private:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	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
Max Kellermann's avatar
Max Kellermann committed
103
	bool Match(const Tag &tag) const;
104 105

	gcc_pure
106
	bool Match(const Song &song) const;
107 108 109 110

	const std::list<Item> &GetItems() const {
		return items;
	}
111

112 113 114 115 116 117 118 119 120 121 122 123
	/**
	 * Is there at least one item with "fold case" enabled?
	 */
	gcc_pure
	bool HasFoldCase() const {
		for (const auto &i : items)
			if (i.GetFoldCase())
				return true;

		return false;
	}

124 125 126 127 128 129
	/**
	 * Returns the "base" specification (if there is one) or an
	 * empty string.
	 */
	gcc_pure
	std::string GetBase() const;
130 131
};

132 133 134
/**
 * @return #TAG_NUM_OF_ITEM_TYPES on error
 */
135
gcc_pure
136
unsigned
Max Kellermann's avatar
Max Kellermann committed
137
locate_parse_type(const char *str);
138

139
#endif