MPD  0.20.6
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 "util/AllocatedString.hxx"
24 #include "Compiler.h"
25 
26 #include <list>
27 
28 #include <stdint.h>
29 #include <time.h>
30 
34 #define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)
35 #define LOCATE_TAG_MODIFIED_SINCE (TAG_NUM_OF_ITEM_TYPES + 2)
36 
37 #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
38 #define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
39 
40 template<typename T> struct ConstBuffer;
41 struct Tag;
42 struct TagItem;
43 struct LightSong;
44 class DetachedSong;
45 
46 class SongFilter {
47 public:
48  class Item {
49  uint8_t tag;
50 
51  bool fold_case;
52 
53  AllocatedString<> value;
54 
58  time_t time;
59 
60  public:
61  gcc_nonnull(3)
62  Item(unsigned tag, const char *value, bool fold_case=false);
63  Item(unsigned tag, time_t time);
64 
65  Item(const Item &other) = delete;
66  Item(Item &&) = default;
67 
68  Item &operator=(const Item &other) = delete;
69 
70  unsigned GetTag() const {
71  return tag;
72  }
73 
74  bool GetFoldCase() const {
75  return fold_case;
76  }
77 
78  const char *GetValue() const {
79  return value.c_str();
80  }
81 
83  bool StringMatch(const char *s) const;
84 
85  gcc_pure
86  bool Match(const TagItem &tag_item) const;
87 
88  gcc_pure
89  bool Match(const Tag &tag) const;
90 
91  gcc_pure
92  bool Match(const DetachedSong &song) const;
93 
94  gcc_pure
95  bool Match(const LightSong &song) const;
96  };
97 
98 private:
99  std::list<Item> items;
100 
101 public:
102  SongFilter() = default;
103 
104  gcc_nonnull(3)
105  SongFilter(unsigned tag, const char *value, bool fold_case=false);
106 
107  ~SongFilter();
108 
109  gcc_nonnull(2,3)
110  bool Parse(const char *tag, const char *value, bool fold_case=false);
111 
112  bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
113 
114  gcc_pure
115  bool Match(const Tag &tag) const;
116 
117  gcc_pure
118  bool Match(const DetachedSong &song) const;
119 
120  gcc_pure
121  bool Match(const LightSong &song) const;
122 
123  const std::list<Item> &GetItems() const {
124  return items;
125  }
126 
127  gcc_pure
128  bool IsEmpty() const {
129  return items.empty();
130  }
131 
135  gcc_pure
136  bool HasFoldCase() const {
137  for (const auto &i : items)
138  if (i.GetFoldCase())
139  return true;
140 
141  return false;
142  }
143 
147  gcc_pure
148  bool HasOtherThanBase() const;
149 
154  gcc_pure
155  const char *GetBase() const;
156 };
157 
161 gcc_pure
162 unsigned
163 locate_parse_type(const char *str);
164 
165 #endif
The meta information about a song file.
Definition: Tag.hxx:34
gcc_pure bool IsEmpty() const
Definition: SongFilter.hxx:128
gcc_pure bool Match(const TagItem &tag_item) const
gcc_nonnull(3) Item(unsigned tag
bool Parse(ConstBuffer< const char * > args, bool fold_case=false)
const std::list< Item > & GetItems() const
Definition: SongFilter.hxx:123
A string pointer whose memory is managed by this class.
Definition: Collate.hxx:26
One tag value.
Definition: TagItem.hxx:30
gcc_pure const char * GetBase() const
Returns the "base" specification (if there is one) or nullptr.
const char * GetValue() const
Definition: SongFilter.hxx:78
unsigned GetTag() const
Definition: SongFilter.hxx:70
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
#define gcc_pure
Definition: Compiler.h:116
gcc_pure unsigned locate_parse_type(const char *str)
constexpr const_pointer_type c_str() const
gcc_pure bool HasFoldCase() const
Is there at least one item with "fold case" enabled?
Definition: SongFilter.hxx:136
A reference to a song file.
Definition: LightSong.hxx:40
gcc_pure bool HasOtherThanBase() const
Does this filter contain constraints other than "base"?
bool GetFoldCase() const
Definition: SongFilter.hxx:74