MPD  0.20.15
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 "util/AllocatedString.hxx"
25 #include "Compiler.h"
26 
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  AllocatedString<> 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  Item(const Item &other) = delete;
70  Item(Item &&) = default;
71 
72  Item &operator=(const Item &other) = delete;
73 
74  unsigned GetTag() const {
75  return tag;
76  }
77 
78  bool GetFoldCase() const {
79  return fold_case;
80  }
81 
82  const char *GetValue() const {
83  return value.c_str();
84  }
85 
87  bool StringMatch(const char *s) const noexcept;
88 
89  gcc_pure
90  bool Match(const TagItem &tag_item) const noexcept;
91 
92  gcc_pure
93  bool Match(const Tag &tag) const noexcept;
94 
95  gcc_pure
96  bool Match(const DetachedSong &song) const noexcept;
97 
98  gcc_pure
99  bool Match(const LightSong &song) const noexcept;
100  };
101 
102 private:
103  std::list<Item> items;
104 
105 public:
106  SongFilter() = default;
107 
108  gcc_nonnull(3)
109  SongFilter(unsigned tag, const char *value, bool fold_case=false);
110 
111  ~SongFilter();
112 
113  gcc_nonnull(2,3)
114  bool Parse(const char *tag, const char *value, bool fold_case=false);
115 
116  bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
117 
118  gcc_pure
119  bool Match(const Tag &tag) const noexcept;
120 
121  gcc_pure
122  bool Match(const DetachedSong &song) const noexcept;
123 
124  gcc_pure
125  bool Match(const LightSong &song) const noexcept;
126 
127  const std::list<Item> &GetItems() const noexcept {
128  return items;
129  }
130 
131  gcc_pure
132  bool IsEmpty() const noexcept {
133  return items.empty();
134  }
135 
139  gcc_pure
140  bool HasFoldCase() const noexcept {
141  for (const auto &i : items)
142  if (i.GetFoldCase())
143  return true;
144 
145  return false;
146  }
147 
151  gcc_pure
152  bool HasOtherThanBase() const noexcept;
153 
158  gcc_pure
159  const char *GetBase() const noexcept;
160 };
161 
165 gcc_pure
166 unsigned
167 locate_parse_type(const char *str) noexcept;
168 
169 #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:127
unsigned GetTag() const
Definition: SongFilter.hxx:74
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:140
bool GetFoldCase() const
Definition: SongFilter.hxx:78
A string pointer whose memory is managed by this class.
Definition: Util.hxx:29
One tag value.
Definition: TagItem.hxx:30
constexpr const_pointer_type c_str() const
const char * GetValue() const
Definition: SongFilter.hxx:82
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:132
#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
A reference to a song file.
Definition: LightSong.hxx:40