mpd/src/song/Filter.hxx

104 lines
2.2 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
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
#include "AndSongFilter.hxx"
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
2012-08-29 19:27:03 +02:00
/**
* Special value for the db_selection_print() sort parameter.
*/
#define SORT_TAG_LAST_MODIFIED (TAG_NUM_OF_ITEM_TYPES + 3)
/**
* Special value for QueueSelection::sort
*/
#define SORT_TAG_PRIO (TAG_NUM_OF_ITEM_TYPES + 4)
/**
* Special value for the db_selection_print() sort parameter.
*/
#define SORT_TAG_ADDED (TAG_NUM_OF_ITEM_TYPES + 5)
enum TagType : uint8_t;
struct LightSong;
class SongFilter {
AndSongFilter and_filter;
2012-08-29 19:27:03 +02:00
public:
SongFilter() = default;
SongFilter(TagType tag, const char *value, bool fold_case=false);
2012-08-29 19:27:03 +02:00
~SongFilter();
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;
private:
static ISongFilterPtr ParseExpression(const char *&s, bool fold_case=false);
void Parse(const char *tag, const char *value, bool fold_case=false);
2012-08-29 19:27:03 +02:00
public:
/**
* Throws on error.
*/
void Parse(std::span<const char *const> args, bool fold_case=false);
2012-08-29 19:27:03 +02:00
void Optimize() noexcept;
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
bool Match(const LightSong &song) const noexcept;
const auto &GetItems() const noexcept {
return and_filter.GetItems();
}
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
bool IsEmpty() const noexcept {
return and_filter.IsEmpty();
}
/**
* Is there at least one item with "fold case" enabled?
*/
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
bool HasFoldCase() const noexcept;
/**
* Does this filter contain constraints other than "base"?
*/
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
bool HasOtherThanBase() const noexcept;
/**
* Returns the "base" specification (if there is one) or
* nullptr.
*/
2021-10-13 11:28:04 +02:00
[[gnu::pure]]
const char *GetBase() const noexcept;
/**
* 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.
*/
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