2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 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
|
|
|
|
2018-08-02 13:54:36 +02:00
|
|
|
#include "AndSongFilter.hxx"
|
2018-08-20 16:19:17 +02:00
|
|
|
#include "util/Compiler.h"
|
2011-09-13 21:36:51 +02:00
|
|
|
|
2020-03-13 01:08:53 +01:00
|
|
|
#include <cstdint>
|
2018-01-19 23:35:36 +01:00
|
|
|
#include <string>
|
2020-04-02 19:36:22 +02:00
|
|
|
#include <string_view>
|
2012-08-29 19:27:03 +02:00
|
|
|
|
2017-12-18 21:36:47 +01:00
|
|
|
/**
|
|
|
|
* Special value for the db_selection_print() sort parameter.
|
|
|
|
*/
|
|
|
|
#define SORT_TAG_LAST_MODIFIED (TAG_NUM_OF_ITEM_TYPES + 3)
|
|
|
|
|
2014-04-24 09:43:08 +02:00
|
|
|
template<typename T> struct ConstBuffer;
|
2018-07-25 07:58:35 +02:00
|
|
|
enum TagType : uint8_t;
|
2014-01-19 10:51:34 +01:00
|
|
|
struct LightSong;
|
2018-07-29 18:39:47 +02:00
|
|
|
|
|
|
|
class SongFilter {
|
|
|
|
AndSongFilter and_filter;
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
public:
|
|
|
|
SongFilter() = default;
|
|
|
|
|
|
|
|
gcc_nonnull(3)
|
2018-07-25 07:58:35 +02:00
|
|
|
SongFilter(TagType tag, const char *value, bool fold_case=false);
|
2012-08-29 19:27:03 +02:00
|
|
|
|
|
|
|
~SongFilter();
|
|
|
|
|
2018-07-25 07:58:35 +02:00
|
|
|
SongFilter(SongFilter &&) = default;
|
|
|
|
SongFilter &operator=(SongFilter &&) = default;
|
|
|
|
|
2018-07-24 22:11:14 +02:00
|
|
|
/**
|
|
|
|
* Convert this object into an "expression". This is
|
|
|
|
* only useful for debugging.
|
|
|
|
*/
|
|
|
|
std::string ToExpression() const noexcept;
|
|
|
|
|
2018-07-21 07:21:27 +02:00
|
|
|
private:
|
2018-07-30 09:56:57 +02:00
|
|
|
static ISongFilterPtr ParseExpression(const char *&s, bool fold_case=false);
|
2018-07-24 19:21:51 +02:00
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
gcc_nonnull(2,3)
|
2018-07-21 07:20:59 +02:00
|
|
|
void Parse(const char *tag, const char *value, bool fold_case=false);
|
2012-08-29 19:27:03 +02:00
|
|
|
|
2018-07-21 07:21:27 +02:00
|
|
|
public:
|
2018-07-21 07:20:59 +02:00
|
|
|
/**
|
|
|
|
* Throws on error.
|
|
|
|
*/
|
|
|
|
void Parse(ConstBuffer<const char *> args, bool fold_case=false);
|
2012-08-29 19:27:03 +02:00
|
|
|
|
2018-08-02 19:42:53 +02:00
|
|
|
void Optimize() noexcept;
|
|
|
|
|
2012-08-29 19:27:03 +02: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
|
|
|
|
2018-07-25 07:58:35 +02:00
|
|
|
const auto &GetItems() const noexcept {
|
2018-07-29 18:39:47 +02:00
|
|
|
return and_filter.GetItems();
|
2013-10-29 20:47:52 +01:00
|
|
|
}
|
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 {
|
2018-07-29 18:39:47 +02:00
|
|
|
return and_filter.IsEmpty();
|
2014-06-23 09:12:51 +02:00
|
|
|
}
|
|
|
|
|
2013-10-30 10:00:57 +01:00
|
|
|
/**
|
|
|
|
* Is there at least one item with "fold case" enabled?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2018-07-25 07:58:35 +02:00
|
|
|
bool HasFoldCase() const noexcept;
|
2013-10-30 10:00:57 +01:00
|
|
|
|
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;
|
2018-01-19 23:35:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-04-02 19:36:22 +02:00
|
|
|
SongFilter WithoutBasePrefix(std::string_view prefix) const noexcept;
|
2012-08-29 19:27:03 +02:00
|
|
|
};
|
|
|
|
|
2008-08-28 20:01:08 +02:00
|
|
|
#endif
|