aboutsummaryrefslogtreecommitdiff
path: root/src/PlaylistVector.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-02 22:16:52 +0100
committerMax Kellermann <max@duempel.org>2013-01-03 02:25:06 +0100
commit9023ba4a81d597c8694432655833cf23d83c6cde (patch)
tree304c2465ea160297dff17302f36c4cc38687ccb6 /src/PlaylistVector.cxx
parent83488848e1091024a0a307b1539c1a85762ee1f1 (diff)
PlaylistVector: use std::list
Diffstat (limited to 'src/PlaylistVector.cxx')
-rw-r--r--src/PlaylistVector.cxx55
1 files changed, 16 insertions, 39 deletions
diff --git a/src/PlaylistVector.cxx b/src/PlaylistVector.cxx
index f1f13567..06c7b9ff 100644
--- a/src/PlaylistVector.cxx
+++ b/src/PlaylistVector.cxx
@@ -21,71 +21,48 @@
#include "PlaylistVector.hxx"
#include "DatabaseLock.hxx"
+#include <algorithm>
+
#include <assert.h>
#include <string.h>
#include <glib.h>
-void
-playlist_vector_deinit(struct list_head *pv)
-{
- assert(pv != NULL);
-
- PlaylistInfo *pm, *n;
- playlist_vector_for_each_safe(pm, n, pv)
- delete pm;
-}
-
-PlaylistInfo *
-playlist_vector_find(struct list_head *pv, const char *name)
+PlaylistVector::iterator
+PlaylistVector::find(const char *name)
{
assert(holding_db_lock());
- assert(pv != NULL);
assert(name != NULL);
- PlaylistInfo *pm;
- playlist_vector_for_each(pm, pv)
- if (pm->name.compare(name) == 0)
- return pm;
-
- return NULL;
-}
-
-void
-playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi)
-{
- assert(holding_db_lock());
-
- PlaylistInfo *pm = new PlaylistInfo(std::move(pi));
- list_add_tail(&pm->siblings, pv);
+ return std::find_if(begin(), end(),
+ PlaylistInfo::CompareName(name));
}
bool
-playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi)
+PlaylistVector::UpdateOrInsert(PlaylistInfo &&pi)
{
assert(holding_db_lock());
- PlaylistInfo *pm = playlist_vector_find(pv, pi.name.c_str());
- if (pm != NULL) {
- if (pi.mtime == pm->mtime)
+ auto i = find(pi.name.c_str());
+ if (i != end()) {
+ if (pi.mtime == i->mtime)
return false;
- pm->mtime = pi.mtime;
+ i->mtime = pi.mtime;
} else
- playlist_vector_add(pv, std::move(pi));
+ push_back(std::move(pi));
return true;
}
bool
-playlist_vector_remove(struct list_head *pv, const char *name)
+PlaylistVector::erase(const char *name)
{
assert(holding_db_lock());
- PlaylistInfo *pm = playlist_vector_find(pv, name);
- if (pm == NULL)
+ auto i = find(name);
+ if (i == end())
return false;
- list_del(&pm->siblings);
- delete pm;
+ erase(i);
return true;
}