db/LightSong: make Tag a reference
This enforces the "not nullptr" rule.
This commit is contained in:
parent
ebc006ab52
commit
b9ff6383a4
@ -26,18 +26,17 @@
|
||||
DetachedSong::DetachedSong(const LightSong &other)
|
||||
:uri(other.GetURI()),
|
||||
real_uri(other.real_uri != nullptr ? other.real_uri : ""),
|
||||
tag(*other.tag),
|
||||
tag(other.tag),
|
||||
mtime(other.mtime),
|
||||
start_time(other.start_time),
|
||||
end_time(other.end_time) {}
|
||||
|
||||
DetachedSong::operator LightSong() const noexcept
|
||||
{
|
||||
LightSong result;
|
||||
LightSong result(tag);
|
||||
result.directory = nullptr;
|
||||
result.uri = uri.c_str();
|
||||
result.real_uri = real_uri.empty() ? nullptr : real_uri.c_str();
|
||||
result.tag = &tag;
|
||||
result.mtime = mtime;
|
||||
result.start_time = start_time;
|
||||
result.end_time = end_time;
|
||||
|
@ -164,7 +164,7 @@ SongFilter::Item::Match(const LightSong &song) const noexcept
|
||||
return StringMatch(uri.c_str());
|
||||
}
|
||||
|
||||
return Match(*song.tag);
|
||||
return Match(song.tag);
|
||||
}
|
||||
|
||||
SongFilter::SongFilter(unsigned tag, const char *value, bool fold_case)
|
||||
|
@ -92,7 +92,7 @@ song_print_info(Response &r, const LightSong &song, bool base) noexcept
|
||||
if (!IsNegative(song.mtime))
|
||||
time_print(r, "Last-Modified", song.mtime);
|
||||
|
||||
tag_print(r, *song.tag);
|
||||
tag_print(r, song.tag);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -97,9 +97,7 @@ static void
|
||||
GroupCountVisitor(TagCountMap &map, TagType group,
|
||||
const LightSong &song) noexcept
|
||||
{
|
||||
assert(song.tag != nullptr);
|
||||
|
||||
const Tag &tag = *song.tag;
|
||||
const Tag &tag = song.tag;
|
||||
if (!CollectGroupCounts(map, group, tag) && group == TAG_ALBUM_ARTIST)
|
||||
/* fall back to "Artist" if no "AlbumArtist" was found */
|
||||
CollectGroupCounts(map, TAG_ARTIST, tag);
|
||||
|
@ -105,7 +105,7 @@ PrintSongBrief(Response &r, bool base, const LightSong &song) noexcept
|
||||
{
|
||||
song_print_uri(r, song, base);
|
||||
|
||||
if (song.tag->has_playlist)
|
||||
if (song.tag.has_playlist)
|
||||
/* this song file has an embedded CUE sheet */
|
||||
print_playlist_in_directory(r, base,
|
||||
song.directory, song.uri);
|
||||
@ -116,7 +116,7 @@ PrintSongFull(Response &r, bool base, const LightSong &song) noexcept
|
||||
{
|
||||
song_print_info(r, song, base);
|
||||
|
||||
if (song.tag->has_playlist)
|
||||
if (song.tag.has_playlist)
|
||||
/* this song file has an embedded CUE sheet */
|
||||
print_playlist_in_directory(r, base,
|
||||
song.directory, song.uri);
|
||||
|
@ -65,7 +65,7 @@ StatsVisitSong(DatabaseStats &stats, StringSet &artists, StringSet &albums,
|
||||
{
|
||||
++stats.song_count;
|
||||
|
||||
StatsVisitTag(stats, artists, albums, *song.tag);
|
||||
StatsVisitTag(stats, artists, albums, song.tag);
|
||||
}
|
||||
|
||||
DatabaseStats
|
||||
|
@ -25,10 +25,10 @@ LightSong::GetDuration() const noexcept
|
||||
{
|
||||
SongTime a = start_time, b = end_time;
|
||||
if (!b.IsPositive()) {
|
||||
if (tag->duration.IsNegative())
|
||||
return tag->duration;
|
||||
if (tag.duration.IsNegative())
|
||||
return tag.duration;
|
||||
|
||||
b = SongTime(tag->duration);
|
||||
b = SongTime(tag.duration);
|
||||
}
|
||||
|
||||
return SignedSongTime(b - a);
|
||||
|
@ -57,9 +57,9 @@ struct LightSong {
|
||||
const char *real_uri;
|
||||
|
||||
/**
|
||||
* Must not be nullptr.
|
||||
* Metadata.
|
||||
*/
|
||||
const Tag *tag;
|
||||
const Tag &tag;
|
||||
|
||||
/**
|
||||
* The time stamp of the last file modification. A negative
|
||||
@ -78,6 +78,9 @@ struct LightSong {
|
||||
*/
|
||||
SongTime end_time;
|
||||
|
||||
explicit LightSong(const Tag &_tag) noexcept
|
||||
:tag(_tag) {}
|
||||
|
||||
gcc_pure
|
||||
std::string GetURI() const noexcept {
|
||||
if (directory == nullptr)
|
||||
|
@ -31,8 +31,7 @@ static void
|
||||
CollectTags(TagSet &set, TagType tag_type, TagMask group_mask,
|
||||
const LightSong &song)
|
||||
{
|
||||
assert(song.tag != nullptr);
|
||||
const Tag &tag = *song.tag;
|
||||
const Tag &tag = song.tag;
|
||||
|
||||
set.InsertUnique(tag, tag_type, group_mask);
|
||||
}
|
||||
|
@ -203,11 +203,11 @@ Copy(TagBuilder &tag, TagType d_tag,
|
||||
}
|
||||
|
||||
ProxySong::ProxySong(const mpd_song *song)
|
||||
:LightSong(tag2)
|
||||
{
|
||||
directory = nullptr;
|
||||
uri = mpd_song_get_uri(song);
|
||||
real_uri = nullptr;
|
||||
tag = &tag2;
|
||||
|
||||
const auto _mtime = mpd_song_get_last_modified(song);
|
||||
mtime = _mtime > 0
|
||||
|
@ -98,12 +98,11 @@ Song::GetURI() const noexcept
|
||||
LightSong
|
||||
Song::Export() const noexcept
|
||||
{
|
||||
LightSong dest;
|
||||
LightSong dest(tag);
|
||||
dest.directory = parent->IsRoot()
|
||||
? nullptr : parent->GetPath();
|
||||
dest.uri = uri;
|
||||
dest.real_uri = nullptr;
|
||||
dest.tag = &tag;
|
||||
dest.mtime = mtime;
|
||||
dest.start_time = start_time;
|
||||
dest.end_time = end_time;
|
||||
|
@ -55,13 +55,13 @@ class UpnpSong : public LightSong {
|
||||
|
||||
public:
|
||||
UpnpSong(UPnPDirObject &&object, std::string &&_uri)
|
||||
:uri2(std::move(_uri)),
|
||||
:LightSong(tag2),
|
||||
uri2(std::move(_uri)),
|
||||
real_uri2(std::move(object.url)),
|
||||
tag2(std::move(object.tag)) {
|
||||
directory = nullptr;
|
||||
uri = uri2.c_str();
|
||||
real_uri = real_uri2.c_str();
|
||||
tag = &tag2;
|
||||
mtime = std::chrono::system_clock::time_point::min();
|
||||
start_time = end_time = SongTime::zero();
|
||||
}
|
||||
@ -321,11 +321,10 @@ visitSong(const UPnPDirObject &meta, const char *path,
|
||||
if (!visit_song)
|
||||
return;
|
||||
|
||||
LightSong song;
|
||||
LightSong song(meta.tag);
|
||||
song.directory = nullptr;
|
||||
song.uri = path;
|
||||
song.real_uri = meta.url.c_str();
|
||||
song.tag = &meta.tag;
|
||||
song.mtime = std::chrono::system_clock::time_point::min();
|
||||
song.start_time = song.end_time = SongTime::zero();
|
||||
|
||||
|
@ -50,7 +50,7 @@ UpdatePlaylistSong(const Database &db, DetachedSong &song)
|
||||
}
|
||||
|
||||
song.SetLastModified(original->mtime);
|
||||
song.SetTag(*original->tag);
|
||||
song.SetTag(original->tag);
|
||||
|
||||
db.ReturnSong(original);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user