1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* Copyright 2003-2017 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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.
*
* 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.
*/
#ifndef MPD_SONG_FILTER_HXX
#define MPD_SONG_FILTER_HXX
#include "lib/icu/Compare.hxx"
#include "Compiler.h"
#include <string>
#include <list>
#include <chrono>
#include <stdint.h>
/**
* Limit the search to files within the given directory.
*/
#define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)
#define LOCATE_TAG_MODIFIED_SINCE (TAG_NUM_OF_ITEM_TYPES + 2)
/**
* Special value for the db_selection_print() sort parameter.
*/
#define SORT_TAG_LAST_MODIFIED (TAG_NUM_OF_ITEM_TYPES + 3)
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
template<typename T> struct ConstBuffer;
struct Tag;
struct TagItem;
struct LightSong;
class DetachedSong;
class SongFilter {
public:
class Item {
uint8_t tag;
std::string value;
/**
* This value is only set if case folding is enabled.
*/
IcuCompare fold_case;
/**
* For #LOCATE_TAG_MODIFIED_SINCE
*/
std::chrono::system_clock::time_point time;
public:
gcc_nonnull(3)
Item(unsigned tag, const char *value, bool fold_case=false);
Item(unsigned tag, std::chrono::system_clock::time_point time);
unsigned GetTag() const {
return tag;
}
bool GetFoldCase() const {
return fold_case;
}
const char *GetValue() const {
return value.c_str();
}
gcc_pure gcc_nonnull(2)
bool StringMatch(const char *s) const noexcept;
gcc_pure
bool Match(const TagItem &tag_item) const noexcept;
gcc_pure
bool Match(const Tag &tag) const noexcept;
gcc_pure
bool Match(const DetachedSong &song) const noexcept;
gcc_pure
bool Match(const LightSong &song) const noexcept;
};
private:
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);
bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
gcc_pure
bool Match(const Tag &tag) const noexcept;
gcc_pure
bool Match(const DetachedSong &song) const noexcept;
gcc_pure
bool Match(const LightSong &song) const noexcept;
const std::list<Item> &GetItems() const noexcept {
return items;
}
gcc_pure
bool IsEmpty() const noexcept {
return items.empty();
}
/**
* Is there at least one item with "fold case" enabled?
*/
gcc_pure
bool HasFoldCase() const noexcept {
for (const auto &i : items)
if (i.GetFoldCase())
return true;
return false;
}
/**
* Does this filter contain constraints other than "base"?
*/
gcc_pure
bool HasOtherThanBase() const noexcept;
/**
* Returns the "base" specification (if there is one) or
* nullptr.
*/
gcc_pure
const char *GetBase() const noexcept;
/**
* Create a copy of the filter with the given prefix stripped
* from all #LOCATE_TAG_BASE_TYPE items. This is used to
* filter songs in mounted databases.
*/
SongFilter WithoutBasePrefix(const char *prefix) const noexcept;
};
/**
* @return #TAG_NUM_OF_ITEM_TYPES on error
*/
gcc_pure
unsigned
locate_parse_type(const char *str) noexcept;
#endif
|