db/simple/Song: make "parent" a reference, not a pointer
This commit is contained in:
parent
1bfede120a
commit
f4d0bd8205
@ -109,12 +109,11 @@ Song::LoadFromArchive(ArchiveFile &archive, const char *name_utf8,
|
|||||||
bool
|
bool
|
||||||
Song::UpdateFileInArchive(ArchiveFile &archive) noexcept
|
Song::UpdateFileInArchive(ArchiveFile &archive) noexcept
|
||||||
{
|
{
|
||||||
assert(parent != nullptr);
|
assert(parent.device == DEVICE_INARCHIVE);
|
||||||
assert(parent->device == DEVICE_INARCHIVE);
|
|
||||||
|
|
||||||
std::string path_utf8(uri);
|
std::string path_utf8(uri);
|
||||||
|
|
||||||
for (const Directory *directory = parent;
|
for (const Directory *directory = &parent;
|
||||||
directory->parent != nullptr &&
|
directory->parent != nullptr &&
|
||||||
directory->parent->device == DEVICE_INARCHIVE;
|
directory->parent->device == DEVICE_INARCHIVE;
|
||||||
directory = directory->parent) {
|
directory = directory->parent) {
|
||||||
|
@ -167,7 +167,7 @@ Directory::AddSong(SongPtr song) noexcept
|
|||||||
{
|
{
|
||||||
assert(holding_db_lock());
|
assert(holding_db_lock());
|
||||||
assert(song != nullptr);
|
assert(song != nullptr);
|
||||||
assert(song->parent == this);
|
assert(&song->parent == this);
|
||||||
|
|
||||||
songs.push_back(*song.release());
|
songs.push_back(*song.release());
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ Directory::RemoveSong(Song *song) noexcept
|
|||||||
{
|
{
|
||||||
assert(holding_db_lock());
|
assert(holding_db_lock());
|
||||||
assert(song != nullptr);
|
assert(song != nullptr);
|
||||||
assert(song->parent == this);
|
assert(&song->parent == this);
|
||||||
|
|
||||||
songs.erase(songs.iterator_to(*song));
|
songs.erase(songs.iterator_to(*song));
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ Directory::FindSong(const char *name_utf8) const noexcept
|
|||||||
assert(name_utf8 != nullptr);
|
assert(name_utf8 != nullptr);
|
||||||
|
|
||||||
for (auto &song : songs) {
|
for (auto &song : songs) {
|
||||||
assert(song.parent == this);
|
assert(&song.parent == this);
|
||||||
|
|
||||||
if (song.uri == name_utf8)
|
if (song.uri == name_utf8)
|
||||||
return &song;
|
return &song;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
Song::Song(StringView _uri, Directory &_parent) noexcept
|
Song::Song(StringView _uri, Directory &_parent) noexcept
|
||||||
:parent(&_parent), uri(_uri.data, _uri.size)
|
:parent(_parent), uri(_uri.data, _uri.size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ Song::NewFile(const char *path, Directory &parent) noexcept
|
|||||||
std::string
|
std::string
|
||||||
Song::GetURI() const noexcept
|
Song::GetURI() const noexcept
|
||||||
{
|
{
|
||||||
if (parent->IsRoot())
|
if (parent.IsRoot())
|
||||||
return uri;
|
return uri;
|
||||||
else {
|
else {
|
||||||
const char *path = parent->GetPath();
|
const char *path = parent.GetPath();
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
result.reserve(strlen(path) + 1 + uri.length());
|
result.reserve(strlen(path) + 1 + uri.length());
|
||||||
@ -74,8 +74,8 @@ LightSong
|
|||||||
Song::Export() const noexcept
|
Song::Export() const noexcept
|
||||||
{
|
{
|
||||||
LightSong dest(uri.c_str(), tag);
|
LightSong dest(uri.c_str(), tag);
|
||||||
if (!parent->IsRoot())
|
if (!parent.IsRoot())
|
||||||
dest.directory = parent->GetPath();
|
dest.directory = parent.GetPath();
|
||||||
dest.mtime = mtime;
|
dest.mtime = mtime;
|
||||||
dest.start_time = start_time;
|
dest.start_time = start_time;
|
||||||
dest.end_time = end_time;
|
dest.end_time = end_time;
|
||||||
|
@ -60,10 +60,9 @@ struct Song {
|
|||||||
Tag tag;
|
Tag tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The #Directory that contains this song. Must be
|
* The #Directory that contains this song.
|
||||||
* non-nullptr.
|
|
||||||
*/
|
*/
|
||||||
Directory *const parent;
|
Directory &parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time stamp of the last file modification. A negative
|
* The time stamp of the last file modification. A negative
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
void
|
void
|
||||||
DatabaseEditor::DeleteSong(Directory &dir, Song *del)
|
DatabaseEditor::DeleteSong(Directory &dir, Song *del)
|
||||||
{
|
{
|
||||||
assert(del->parent == &dir);
|
assert(&del->parent == &dir);
|
||||||
|
|
||||||
/* first, prevent traversers in main task from getting this */
|
/* first, prevent traversers in main task from getting this */
|
||||||
dir.RemoveSong(del);
|
dir.RemoveSong(del);
|
||||||
@ -65,7 +65,7 @@ DatabaseEditor::ClearDirectory(Directory &directory)
|
|||||||
});
|
});
|
||||||
|
|
||||||
directory.ForEachSongSafe([this, &directory](Song &song){
|
directory.ForEachSongSafe([this, &directory](Song &song){
|
||||||
assert(song.parent == &directory);
|
assert(&song.parent == &directory);
|
||||||
DeleteSong(directory, &song);
|
DeleteSong(directory, &song);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ UpdateWalk::RemoveExcludedFromDirectory(Directory &directory,
|
|||||||
});
|
});
|
||||||
|
|
||||||
directory.ForEachSongSafe([&](Song &song){
|
directory.ForEachSongSafe([&](Song &song){
|
||||||
assert(song.parent == &directory);
|
assert(&song.parent == &directory);
|
||||||
|
|
||||||
const auto name_fs = AllocatedPath::FromUTF8(song.uri.c_str());
|
const auto name_fs = AllocatedPath::FromUTF8(song.uri.c_str());
|
||||||
if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
|
if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user