db/Interface: pass std::string_view to GetSong()
This commit is contained in:
parent
212401d687
commit
57fb153c5d
|
@ -75,7 +75,7 @@ public:
|
|||
* directory (UTF-8)
|
||||
* @return a pointer that must be released with ReturnSong()
|
||||
*/
|
||||
virtual const LightSong *GetSong(const char *uri_utf8) const = 0;
|
||||
virtual const LightSong *GetSong(std::string_view uri_utf8) const = 0;
|
||||
|
||||
/**
|
||||
* Mark the song object as "unused". Call this on objects
|
||||
|
|
|
@ -22,12 +22,6 @@
|
|||
|
||||
#include <string_view>
|
||||
|
||||
static inline bool
|
||||
isRootDirectory(const char *name)
|
||||
{
|
||||
return name[0] == 0 || (name[0] == '/' && name[1] == 0);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
isRootDirectory(std::string_view name) noexcept
|
||||
{
|
||||
|
|
|
@ -121,7 +121,7 @@ public:
|
|||
|
||||
void Open() override;
|
||||
void Close() noexcept override;
|
||||
const LightSong *GetSong(const char *uri_utf8) const override;
|
||||
const LightSong *GetSong(std::string_view uri_utf8) const override;
|
||||
void ReturnSong(const LightSong *song) const noexcept override;
|
||||
|
||||
void Visit(const DatabaseSelection &selection,
|
||||
|
@ -641,12 +641,12 @@ ProxyDatabase::OnIdle() noexcept
|
|||
}
|
||||
|
||||
const LightSong *
|
||||
ProxyDatabase::GetSong(const char *uri) const
|
||||
ProxyDatabase::GetSong(std::string_view uri) const
|
||||
{
|
||||
// TODO: eliminate the const_cast
|
||||
const_cast<ProxyDatabase *>(this)->EnsureConnected();
|
||||
|
||||
if (!mpd_send_list_meta(connection, uri))
|
||||
if (!mpd_send_list_meta(connection, std::string(uri).c_str()))
|
||||
ThrowError(connection);
|
||||
|
||||
struct mpd_song *song = mpd_recv_song(connection);
|
||||
|
|
|
@ -197,7 +197,7 @@ SimpleDatabase::Close() noexcept
|
|||
}
|
||||
|
||||
const LightSong *
|
||||
SimpleDatabase::GetSong(const char *uri) const
|
||||
SimpleDatabase::GetSong(std::string_view uri) const
|
||||
{
|
||||
assert(root != nullptr);
|
||||
assert(prefixed_light_song == nullptr);
|
||||
|
@ -211,10 +211,8 @@ SimpleDatabase::GetSong(const char *uri) const
|
|||
/* pass the request to the mounted database */
|
||||
protect.unlock();
|
||||
|
||||
/* note: r.rest.data() is actually null-terminated
|
||||
because it points inside the "uri" parameter */
|
||||
const LightSong *song =
|
||||
r.directory->mounted_database->GetSong(r.rest.data());
|
||||
r.directory->mounted_database->GetSong(r.rest);
|
||||
if (song == nullptr)
|
||||
return nullptr;
|
||||
|
||||
|
@ -224,7 +222,7 @@ SimpleDatabase::GetSong(const char *uri) const
|
|||
return prefixed_light_song;
|
||||
}
|
||||
|
||||
if (r.rest.data() == nullptr)
|
||||
if (r.rest.empty())
|
||||
/* it's a directory */
|
||||
throw DatabaseError(DatabaseErrorCode::NOT_FOUND,
|
||||
"No such song");
|
||||
|
|
|
@ -114,7 +114,7 @@ public:
|
|||
void Open() override;
|
||||
void Close() noexcept override;
|
||||
|
||||
const LightSong *GetSong(const char *uri_utf8) const override;
|
||||
const LightSong *GetSong(std::string_view uri_utf8) const override;
|
||||
void ReturnSong(const LightSong *song) const noexcept override;
|
||||
|
||||
void Visit(const DatabaseSelection &selection,
|
||||
|
|
|
@ -62,8 +62,9 @@ class UpnpSong : UpnpSongData, public LightSong {
|
|||
std::string real_uri2;
|
||||
|
||||
public:
|
||||
UpnpSong(UPnPDirObject &&object, std::string &&_uri) noexcept
|
||||
:UpnpSongData(std::move(_uri), std::move(object.tag)),
|
||||
template<typename U>
|
||||
UpnpSong(UPnPDirObject &&object, U &&_uri) noexcept
|
||||
:UpnpSongData(std::forward<U>(_uri), std::move(object.tag)),
|
||||
LightSong(UpnpSongData::uri.c_str(), UpnpSongData::tag),
|
||||
real_uri2(std::move(object.url)) {
|
||||
real_uri = real_uri2.c_str();
|
||||
|
@ -87,7 +88,7 @@ public:
|
|||
|
||||
void Open() override;
|
||||
void Close() noexcept override;
|
||||
const LightSong *GetSong(const char *uri_utf8) const override;
|
||||
const LightSong *GetSong(std::string_view uri_utf8) const override;
|
||||
void ReturnSong(const LightSong *song) const noexcept override;
|
||||
|
||||
void Visit(const DatabaseSelection &selection,
|
||||
|
@ -185,7 +186,7 @@ UpnpDatabase::ReturnSong(const LightSong *_song) const noexcept
|
|||
// Get song info by path. We can receive either the id path, or the titles
|
||||
// one
|
||||
const LightSong *
|
||||
UpnpDatabase::GetSong(const char *uri) const
|
||||
UpnpDatabase::GetSong(std::string_view uri) const
|
||||
{
|
||||
auto vpath = SplitString(uri, '/');
|
||||
if (vpath.empty())
|
||||
|
|
Loading…
Reference in New Issue