MPD  0.20.18
SongFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_SONG_FILTER_HXX
21 #define MPD_SONG_FILTER_HXX
22 
23 #include "lib/icu/Compare.hxx"
24 #include "Compiler.h"
25 
26 #include <string>
27 #include <list>
28 
29 #include <stdint.h>
30 #include <time.h>
31 
35 #define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)
36 #define LOCATE_TAG_MODIFIED_SINCE (TAG_NUM_OF_ITEM_TYPES + 2)
37 
38 #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
39 #define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
40 
41 template<typename T> struct ConstBuffer;
42 struct Tag;
43 struct TagItem;
44 struct LightSong;
45 class DetachedSong;
46 
47 class SongFilter {
48 public:
49  class Item {
50  uint8_t tag;
51 
52  std::string value;
53 
57  IcuCompare fold_case;
58 
62  time_t time;
63 
64  public:
65  gcc_nonnull(3)
66  Item(unsigned tag, const char *value, bool fold_case=false);
67  Item(unsigned tag, time_t time);
68 
69  unsigned GetTag() const {
70  return tag;
71  }
72 
73  bool GetFoldCase() const {
74  return fold_case;
75  }
76 
77  const char *GetValue() const {
78  return value.c_str();
79  }
80 
82  bool StringMatch(const char *s) const noexcept;
83 
84  gcc_pure
85  bool Match(const TagItem &tag_item) const noexcept;
86 
87  gcc_pure
88  bool Match(const Tag &tag) const noexcept;
89 
90  gcc_pure
91  bool Match(const DetachedSong &song) const noexcept;
92 
93  gcc_pure
94  bool Match(const LightSong &song) const noexcept;
95  };
96 
97 private:
98  std::list<Item> items;
99 
100 public:
101  SongFilter() = default;
102 
103  gcc_nonnull(3)
104  SongFilter(unsigned tag, const char *value, bool fold_case=false);
105 
106  ~SongFilter();
107 
108  gcc_nonnull(2,3)
109  bool Parse(const char *tag, const char *value, bool fold_case=false);
110 
111  bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
112 
113  gcc_pure
114  bool Match(const Tag &tag) const noexcept;
115 
116  gcc_pure
117  bool Match(const DetachedSong &song) const noexcept;
118 
119  gcc_pure
120  bool Match(const LightSong &song) const noexcept;
121 
122  const std::list<Item> &GetItems() const noexcept {
123  return items;
124  }
125 
126  gcc_pure
127  bool IsEmpty() const noexcept {
128  return items.empty();
129  }
130 
134  gcc_pure
135  bool HasFoldCase() const noexcept {
136  for (const auto &i : items)
137  if (i.GetFoldCase())
138  return true;
139 
140  return false;
141  }
142 
146  gcc_pure
147  bool HasOtherThanBase() const noexcept;
148 
153  gcc_pure
154  const char *GetBase() const noexcept;
155 
161  SongFilter WithoutBasePrefix(const char *prefix) const noexcept;
162 };
163 
167 gcc_pure
168 unsigned
169 locate_parse_type(const char *str) noexcept;
170 
171 #endif
The meta information about a song file.
Definition: Tag.hxx:34
bool Parse(ConstBuffer< const char *> args, bool fold_case=false)
const std::list< Item > & GetItems() const noexcept
Definition: SongFilter.hxx:122
unsigned GetTag() const
Definition: SongFilter.hxx:69
gcc_nonnull(3) Item(unsigned tag
This class can compare one string ("needle") with lots of other strings ("haystacks") efficiently...
Definition: Compare.hxx:32
gcc_pure unsigned locate_parse_type(const char *str) noexcept
gcc_pure bool HasFoldCase() const noexcept
Is there at least one item with "fold case" enabled?
Definition: SongFilter.hxx:135
bool GetFoldCase() const
Definition: SongFilter.hxx:73
One tag value.
Definition: TagItem.hxx:30
const char * GetValue() const
Definition: SongFilter.hxx:77
gcc_pure const char * GetBase() const noexcept
Returns the "base" specification (if there is one) or nullptr.
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
gcc_pure bool IsEmpty() const noexcept
Definition: SongFilter.hxx:127
#define gcc_pure
Definition: Compiler.h:116
gcc_pure bool HasOtherThanBase() const noexcept
Does this filter contain constraints other than "base"?
gcc_pure bool Match(const TagItem &tag_item) const noexcept
SongFilter WithoutBasePrefix(const char *prefix) const noexcept
Create a copy of the filter with the given prefix stripped from all LOCATE_TAG_BASE_TYPE items...
A reference to a song file.
Definition: LightSong.hxx:40