db/*: use std::span instead of ConstBuffer
This commit is contained in:
parent
4fb8b45111
commit
b9c9a5f1dd
@ -191,11 +191,11 @@ PrintSongUris(Response &r, Partition &partition,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
|
PrintUniqueTags(Response &r, std::span<const TagType> tag_types,
|
||||||
const RecursiveMap<std::string> &map) noexcept
|
const RecursiveMap<std::string> &map) noexcept
|
||||||
{
|
{
|
||||||
const char *const name = tag_item_names[tag_types.front()];
|
const char *const name = tag_item_names[tag_types.front()];
|
||||||
tag_types.pop_front();
|
tag_types = tag_types.subspan(1);
|
||||||
|
|
||||||
for (const auto &[key, tag] : map) {
|
for (const auto &[key, tag] : map) {
|
||||||
r.Fmt(FMT_STRING("{}: {}\n"), name, key);
|
r.Fmt(FMT_STRING("{}: {}\n"), name, key);
|
||||||
@ -207,7 +207,7 @@ PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
|
|||||||
|
|
||||||
void
|
void
|
||||||
PrintUniqueTags(Response &r, Partition &partition,
|
PrintUniqueTags(Response &r, Partition &partition,
|
||||||
ConstBuffer<TagType> tag_types,
|
std::span<const TagType> tag_types,
|
||||||
const SongFilter *filter)
|
const SongFilter *filter)
|
||||||
{
|
{
|
||||||
const Database &db = partition.GetDatabaseOrThrow();
|
const Database &db = partition.GetDatabaseOrThrow();
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
#define MPD_DB_PRINT_H
|
#define MPD_DB_PRINT_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
template<typename T> struct ConstBuffer;
|
|
||||||
enum TagType : uint8_t;
|
enum TagType : uint8_t;
|
||||||
class SongFilter;
|
class SongFilter;
|
||||||
struct DatabaseSelection;
|
struct DatabaseSelection;
|
||||||
@ -44,7 +44,7 @@ PrintSongUris(Response &r, Partition &partition,
|
|||||||
|
|
||||||
void
|
void
|
||||||
PrintUniqueTags(Response &r, Partition &partition,
|
PrintUniqueTags(Response &r, Partition &partition,
|
||||||
ConstBuffer<TagType> tag_types,
|
std::span<const TagType> tag_types,
|
||||||
const SongFilter *filter);
|
const SongFilter *filter);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "tag/Type.h"
|
#include "tag/Type.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct DatabasePlugin;
|
struct DatabasePlugin;
|
||||||
@ -31,7 +32,6 @@ struct DatabaseStats;
|
|||||||
struct DatabaseSelection;
|
struct DatabaseSelection;
|
||||||
struct LightSong;
|
struct LightSong;
|
||||||
template<typename Key> class RecursiveMap;
|
template<typename Key> class RecursiveMap;
|
||||||
template<typename T> struct ConstBuffer;
|
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
const DatabasePlugin &plugin;
|
const DatabasePlugin &plugin;
|
||||||
@ -111,7 +111,7 @@ public:
|
|||||||
* Throws on error.
|
* Throws on error.
|
||||||
*/
|
*/
|
||||||
virtual RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
virtual RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const = 0;
|
std::span<const TagType> tag_types) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws on error.
|
* Throws on error.
|
||||||
|
@ -21,18 +21,18 @@
|
|||||||
#include "Interface.hxx"
|
#include "Interface.hxx"
|
||||||
#include "song/LightSong.hxx"
|
#include "song/LightSong.hxx"
|
||||||
#include "tag/VisitFallback.hxx"
|
#include "tag/VisitFallback.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
|
||||||
#include "util/RecursiveMap.hxx"
|
#include "util/RecursiveMap.hxx"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
CollectUniqueTags(RecursiveMap<std::string> &result,
|
CollectUniqueTags(RecursiveMap<std::string> &result,
|
||||||
const Tag &tag,
|
const Tag &tag,
|
||||||
ConstBuffer<TagType> tag_types) noexcept
|
std::span<const TagType> tag_types) noexcept
|
||||||
{
|
{
|
||||||
if (tag_types.empty())
|
if (tag_types.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto tag_type = tag_types.shift();
|
const auto tag_type = tag_types.front();
|
||||||
|
tag_types = tag_types.subspan(1);
|
||||||
|
|
||||||
VisitTagWithFallbackOrEmpty(tag, tag_type, [&result, &tag, tag_types](const char *value){
|
VisitTagWithFallbackOrEmpty(tag, tag_type, [&result, &tag, tag_types](const char *value){
|
||||||
CollectUniqueTags(result[value], tag, tag_types);
|
CollectUniqueTags(result[value], tag, tag_types);
|
||||||
@ -41,7 +41,7 @@ CollectUniqueTags(RecursiveMap<std::string> &result,
|
|||||||
|
|
||||||
RecursiveMap<std::string>
|
RecursiveMap<std::string>
|
||||||
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
|
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types)
|
std::span<const TagType> tag_types)
|
||||||
{
|
{
|
||||||
RecursiveMap<std::string> result;
|
RecursiveMap<std::string> result;
|
||||||
|
|
||||||
|
@ -22,18 +22,18 @@
|
|||||||
|
|
||||||
#include "tag/Type.h"
|
#include "tag/Type.h"
|
||||||
|
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Database;
|
class Database;
|
||||||
struct DatabaseSelection;
|
struct DatabaseSelection;
|
||||||
template<typename Key> class RecursiveMap;
|
template<typename Key> class RecursiveMap;
|
||||||
template<typename T> struct ConstBuffer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walk the database and collect unique tag values.
|
* Walk the database and collect unique tag values.
|
||||||
*/
|
*/
|
||||||
RecursiveMap<std::string>
|
RecursiveMap<std::string>
|
||||||
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
|
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types);
|
std::span<const TagType> tag_types);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "tag/Builder.hxx"
|
#include "tag/Builder.hxx"
|
||||||
#include "tag/Tag.hxx"
|
#include "tag/Tag.hxx"
|
||||||
#include "tag/ParseName.hxx"
|
#include "tag/ParseName.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
|
||||||
#include "util/RecursiveMap.hxx"
|
#include "util/RecursiveMap.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
@ -136,7 +135,7 @@ public:
|
|||||||
VisitPlaylist visit_playlist) const override;
|
VisitPlaylist visit_playlist) const override;
|
||||||
|
|
||||||
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const override;
|
std::span<const TagType> tag_types) const override;
|
||||||
|
|
||||||
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
||||||
|
|
||||||
@ -440,13 +439,13 @@ SendGroup(mpd_connection *connection, TagType group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
SendGroup(mpd_connection *connection, ConstBuffer<TagType> group)
|
SendGroup(mpd_connection *connection, std::span<const TagType> group)
|
||||||
{
|
{
|
||||||
while (!group.empty()) {
|
while (!group.empty()) {
|
||||||
if (!SendGroup(connection, group.back()))
|
if (!SendGroup(connection, group.back()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
group.pop_back();
|
group = group.first(group.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1010,7 +1009,7 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
|
|||||||
|
|
||||||
RecursiveMap<std::string>
|
RecursiveMap<std::string>
|
||||||
ProxyDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
ProxyDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const
|
std::span<const TagType> tag_types) const
|
||||||
try {
|
try {
|
||||||
// TODO: eliminate the const_cast
|
// TODO: eliminate the const_cast
|
||||||
const_cast<ProxyDatabase *>(this)->EnsureConnected();
|
const_cast<ProxyDatabase *>(this)->EnsureConnected();
|
||||||
@ -1019,8 +1018,7 @@ try {
|
|||||||
if (tag_type2 == MPD_TAG_COUNT)
|
if (tag_type2 == MPD_TAG_COUNT)
|
||||||
throw std::runtime_error("Unsupported tag");
|
throw std::runtime_error("Unsupported tag");
|
||||||
|
|
||||||
auto group = tag_types;
|
const auto group = tag_types.first(tag_types.size() - 1);
|
||||||
group.pop_back();
|
|
||||||
|
|
||||||
if (!mpd_search_db_tags(connection, tag_type2) ||
|
if (!mpd_search_db_tags(connection, tag_type2) ||
|
||||||
!SendConstraints(connection, selection, selection.window) ||
|
!SendConstraints(connection, selection, selection.window) ||
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
#include "fs/FileSystem.hxx"
|
#include "fs/FileSystem.hxx"
|
||||||
#include "util/CharUtil.hxx"
|
#include "util/CharUtil.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
|
||||||
#include "util/RecursiveMap.hxx"
|
#include "util/RecursiveMap.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
@ -334,7 +333,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
|
|||||||
|
|
||||||
RecursiveMap<std::string>
|
RecursiveMap<std::string>
|
||||||
SimpleDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
SimpleDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const
|
std::span<const TagType> tag_types) const
|
||||||
{
|
{
|
||||||
return ::CollectUniqueTags(*this, selection, tag_types);
|
return ::CollectUniqueTags(*this, selection, tag_types);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public:
|
|||||||
VisitPlaylist visit_playlist) const override;
|
VisitPlaylist visit_playlist) const override;
|
||||||
|
|
||||||
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const override;
|
std::span<const TagType> tag_types) const override;
|
||||||
|
|
||||||
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "db/Stats.hxx"
|
#include "db/Stats.hxx"
|
||||||
#include "tag/Table.hxx"
|
#include "tag/Table.hxx"
|
||||||
#include "fs/Traits.hxx"
|
#include "fs/Traits.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
|
||||||
#include "util/RecursiveMap.hxx"
|
#include "util/RecursiveMap.hxx"
|
||||||
#include "util/SplitString.hxx"
|
#include "util/SplitString.hxx"
|
||||||
#include "config/Block.hxx"
|
#include "config/Block.hxx"
|
||||||
@ -101,7 +100,7 @@ public:
|
|||||||
VisitPlaylist visit_playlist) const override;
|
VisitPlaylist visit_playlist) const override;
|
||||||
|
|
||||||
[[nodiscard]] RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
[[nodiscard]] RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const override;
|
std::span<const TagType> tag_types) const override;
|
||||||
|
|
||||||
[[nodiscard]] DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
[[nodiscard]] DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
||||||
|
|
||||||
@ -629,7 +628,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
|
|||||||
|
|
||||||
RecursiveMap<std::string>
|
RecursiveMap<std::string>
|
||||||
UpnpDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
UpnpDatabase::CollectUniqueTags(const DatabaseSelection &selection,
|
||||||
ConstBuffer<TagType> tag_types) const
|
std::span<const TagType> tag_types) const
|
||||||
{
|
{
|
||||||
return ::CollectUniqueTags(*this, selection, tag_types);
|
return ::CollectUniqueTags(*this, selection, tag_types);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user