aboutsummaryrefslogtreecommitdiffstats
path: root/src/Directory.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Directory.cxx (renamed from src/directory.c)66
1 files changed, 41 insertions, 25 deletions
diff --git a/src/directory.c b/src/Directory.cxx
index e886698d6..eeba903d1 100644
--- a/src/directory.c
+++ b/src/Directory.cxx
@@ -19,13 +19,16 @@
#include "config.h"
#include "directory.h"
+#include "SongFilter.hxx"
+
+extern "C" {
#include "song.h"
#include "song_sort.h"
#include "playlist_vector.h"
#include "path.h"
#include "util/list_sort.h"
-#include "db_visitor.h"
#include "db_lock.h"
+}
#include <glib.h>
@@ -33,23 +36,34 @@
#include <string.h>
#include <stdlib.h>
-struct directory *
-directory_new(const char *path, struct directory *parent)
+static directory *
+directory_allocate(const char *path)
{
- struct directory *directory;
- size_t pathlen = strlen(path);
-
assert(path != NULL);
- assert((*path == 0) == (parent == NULL));
- directory = g_malloc0(sizeof(*directory) -
- sizeof(directory->path) + pathlen + 1);
+ const size_t path_size = strlen(path) + 1;
+ directory *directory =
+ (struct directory *)g_malloc0(sizeof(*directory)
+ - sizeof(directory->path)
+ + path_size);
INIT_LIST_HEAD(&directory->children);
INIT_LIST_HEAD(&directory->songs);
INIT_LIST_HEAD(&directory->playlists);
+ memcpy(directory->path, path, path_size);
+
+ return directory;
+}
+
+struct directory *
+directory_new(const char *path, struct directory *parent)
+{
+ assert(path != NULL);
+ assert((*path == 0) == (parent == NULL));
+
+ directory *directory = directory_allocate(path);
+
directory->parent = parent;
- memcpy(directory->path, path, pathlen + 1);
return directory;
}
@@ -277,36 +291,38 @@ directory_sort(struct directory *directory)
}
bool
-directory_walk(const struct directory *directory, bool recursive,
- const struct db_visitor *visitor, void *ctx,
- GError **error_r)
+directory::Walk(bool recursive, const SongFilter *filter,
+ VisitDirectory visit_directory, VisitSong visit_song,
+ VisitPlaylist visit_playlist,
+ GError **error_r) const
{
- assert(directory != NULL);
- assert(visitor != NULL);
assert(error_r == NULL || *error_r == NULL);
- if (visitor->song != NULL) {
+ if (visit_song) {
struct song *song;
- directory_for_each_song(song, directory)
- if (!visitor->song(song, ctx, error_r))
+ directory_for_each_song(song, this)
+ if ((filter == nullptr || filter->Match(*song)) &&
+ !visit_song(*song, error_r))
return false;
}
- if (visitor->playlist != NULL) {
+ if (visit_playlist) {
struct playlist_metadata *i;
- directory_for_each_playlist(i, directory)
- if (!visitor->playlist(i, directory, ctx, error_r))
+ directory_for_each_playlist(i, this)
+ if (!visit_playlist(*i, *this, error_r))
return false;
}
struct directory *child;
- directory_for_each_child(child, directory) {
- if (visitor->directory != NULL &&
- !visitor->directory(child, ctx, error_r))
+ directory_for_each_child(child, this) {
+ if (visit_directory &&
+ !visit_directory(*child, error_r))
return false;
if (recursive &&
- !directory_walk(child, recursive, visitor, ctx, error_r))
+ !child->Walk(recursive, filter,
+ visit_directory, visit_song, visit_playlist,
+ error_r))
return false;
}