2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2007-02-24 04:14:00 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2007-02-24 04:14:00 +01:00
|
|
|
*/
|
|
|
|
|
2012-08-29 19:12:26 +02:00
|
|
|
#ifndef MPD_SONG_FILTER_HXX
|
|
|
|
#define MPD_SONG_FILTER_HXX
|
2008-08-28 20:01:08 +02:00
|
|
|
|
2015-06-25 22:43:55 +02:00
|
|
|
#include "util/AllocatedString.hxx"
|
2013-10-15 09:21:13 +02:00
|
|
|
#include "Compiler.h"
|
2011-09-13 21:36:51 +02:00
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
#include <list>
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
#include <stdint.h>
|
2014-08-11 22:08:26 +02:00
|
|
|
#include <time.h>
|
2007-02-24 01:54:54 +01:00
|
|
|
|
2013-10-29 18:54:34 +01:00
|
|
|
/**
|
|
|
|
* Limit the search to files within the given directory.
|
|
|
|
*/
|
|
|
|
#define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)
|
2014-08-11 22:08:26 +02:00
|
|
|
#define LOCATE_TAG_MODIFIED_SINCE (TAG_NUM_OF_ITEM_TYPES + 2)
|
2013-10-29 18:54:34 +01:00
|
|
|
|
2007-02-24 01:54:54 +01:00
|
|
|
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
|
|
|
|
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
|
|
|
|
|
2014-04-24 09:43:08 +02:00
|
|
|
template<typename T> struct ConstBuffer;
|
2013-07-30 20:11:57 +02:00
|
|
|
struct Tag;
|
|
|
|
struct TagItem;
|
2014-01-19 10:51:34 +01:00
|
|
|
struct LightSong;
|
2014-01-07 21:39:47 +01:00
|
|
|
class DetachedSong;
|
2008-10-08 10:49:11 +02:00
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
class SongFilter {
|
2013-10-29 20:47:52 +01:00
|
|
|
public:
|
2012-08-29 19:27:03 +02:00
|
|
|
class Item {
|
|
|
|
uint8_t tag;
|
|
|
|
|
|
|
|
bool fold_case;
|
|
|
|
|
2015-06-25 22:43:55 +02:00
|
|
|
AllocatedString<> value;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
2014-08-11 22:08:26 +02:00
|
|
|
/**
|
|
|
|
* For #LOCATE_TAG_MODIFIED_SINCE
|
|
|
|
*/
|
|
|
|
time_t time;
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
public:
|
|
|
|
gcc_nonnull(3)
|
|
|
|
Item(unsigned tag, const char *value, bool fold_case=false);
|
2014-08-11 22:08:26 +02:00
|
|
|
Item(unsigned tag, time_t time);
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
Item(const Item &other) = delete;
|
2013-10-29 19:39:17 +01:00
|
|
|
Item(Item &&) = default;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
Item &operator=(const Item &other) = delete;
|
|
|
|
|
|
|
|
unsigned GetTag() const {
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2013-10-30 10:00:57 +01:00
|
|
|
bool GetFoldCase() const {
|
|
|
|
return fold_case;
|
|
|
|
}
|
|
|
|
|
2015-06-25 23:14:40 +02:00
|
|
|
const char *GetValue() const {
|
|
|
|
return value.c_str();
|
2013-10-29 20:47:52 +01:00
|
|
|
}
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
gcc_pure gcc_nonnull(2)
|
2017-05-08 14:44:49 +02:00
|
|
|
bool StringMatch(const char *s) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const TagItem &tag_item) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const Tag &tag) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const DetachedSong &song) const noexcept;
|
2014-01-07 21:39:47 +01:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const LightSong &song) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
};
|
|
|
|
|
2013-10-29 20:47:52 +01:00
|
|
|
private:
|
2012-08-29 19:27:03 +02:00
|
|
|
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);
|
|
|
|
|
2014-04-24 09:43:08 +02:00
|
|
|
bool Parse(ConstBuffer<const char *> args, bool fold_case=false);
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const Tag &tag) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const DetachedSong &song) const noexcept;
|
2013-10-29 20:47:52 +01:00
|
|
|
|
2014-01-07 21:39:47 +01:00
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool Match(const LightSong &song) const noexcept;
|
2014-01-07 21:39:47 +01:00
|
|
|
|
2017-05-08 14:44:49 +02:00
|
|
|
const std::list<Item> &GetItems() const noexcept {
|
2013-10-29 20:47:52 +01:00
|
|
|
return items;
|
|
|
|
}
|
2013-10-29 18:54:34 +01:00
|
|
|
|
2014-06-23 09:12:51 +02:00
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool IsEmpty() const noexcept {
|
2014-06-23 09:12:51 +02:00
|
|
|
return items.empty();
|
|
|
|
}
|
|
|
|
|
2013-10-30 10:00:57 +01:00
|
|
|
/**
|
|
|
|
* Is there at least one item with "fold case" enabled?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool HasFoldCase() const noexcept {
|
2013-10-30 10:00:57 +01:00
|
|
|
for (const auto &i : items)
|
|
|
|
if (i.GetFoldCase())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-23 09:12:51 +02:00
|
|
|
/**
|
|
|
|
* Does this filter contain constraints other than "base"?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
bool HasOtherThanBase() const noexcept;
|
2014-06-23 09:12:51 +02:00
|
|
|
|
2013-10-29 18:54:34 +01:00
|
|
|
/**
|
2015-06-25 23:14:40 +02:00
|
|
|
* Returns the "base" specification (if there is one) or
|
|
|
|
* nullptr.
|
2013-10-29 18:54:34 +01:00
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
const char *GetBase() const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
};
|
|
|
|
|
2012-08-08 00:45:46 +02:00
|
|
|
/**
|
|
|
|
* @return #TAG_NUM_OF_ITEM_TYPES on error
|
|
|
|
*/
|
2012-08-07 23:43:36 +02:00
|
|
|
gcc_pure
|
2012-08-08 00:45:46 +02:00
|
|
|
unsigned
|
2017-05-08 14:44:49 +02:00
|
|
|
locate_parse_type(const char *str) noexcept;
|
2007-02-24 01:54:54 +01:00
|
|
|
|
2008-08-28 20:01:08 +02:00
|
|
|
#endif
|