aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-03 01:36:28 +0100
committerMax Kellermann <max@duempel.org>2013-01-03 01:36:28 +0100
commitf5a92d6cc39ea15ea8aa4cc35ee742a646b12508 (patch)
tree0797bc80790ce919880a43bb032bd991fe7b2a4b
parent3e8047e5831b4cc7dabae596746066698ad7c8cd (diff)
Directory: add constructor and destructor
-rw-r--r--src/Directory.cxx45
-rw-r--r--src/Directory.hxx13
-rw-r--r--test/DumpPlaylist.cxx3
-rw-r--r--test/TestQueuePriority.cxx2
4 files changed, 45 insertions, 18 deletions
diff --git a/src/Directory.cxx b/src/Directory.cxx
index c2c5d281..b67ad3de 100644
--- a/src/Directory.cxx
+++ b/src/Directory.cxx
@@ -36,8 +36,8 @@ extern "C" {
#include <string.h>
#include <stdlib.h>
-static Directory *
-directory_allocate(const char *path)
+inline Directory *
+Directory::Allocate(const char *path)
{
assert(path != NULL);
@@ -46,30 +46,21 @@ directory_allocate(const char *path)
(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);
+ new(directory) Directory(path);
return directory;
}
-Directory *
-Directory::NewGeneric(const char *path, Directory *parent)
+Directory::Directory(const char *_path)
{
- assert(path != NULL);
- assert((*path == 0) == (parent == NULL));
-
- Directory *directory = directory_allocate(path);
-
- directory->parent = parent;
+ INIT_LIST_HEAD(&children);
+ INIT_LIST_HEAD(&songs);
+ INIT_LIST_HEAD(&playlists);
- return directory;
+ strcpy(path, _path);
}
-void
-Directory::Free()
+Directory::~Directory()
{
playlist_vector_deinit(&playlists);
@@ -80,7 +71,25 @@ Directory::Free()
Directory *child, *n;
directory_for_each_child_safe(child, n, this)
child->Free();
+}
+Directory *
+Directory::NewGeneric(const char *path, Directory *parent)
+{
+ assert(path != NULL);
+ assert((*path == 0) == (parent == NULL));
+
+ Directory *directory = Allocate(path);
+
+ directory->parent = parent;
+
+ return directory;
+}
+
+void
+Directory::Free()
+{
+ this->Directory::~Directory();
g_free(this);
}
diff --git a/src/Directory.hxx b/src/Directory.hxx
index 29c69d6d..3b2c6b1a 100644
--- a/src/Directory.hxx
+++ b/src/Directory.hxx
@@ -90,6 +90,19 @@ struct Directory {
bool have_stat; /* not needed if ino_t == dev_t == 0 is impossible */
char path[sizeof(long)];
+protected:
+ Directory(const char *path);
+
+ gcc_malloc gcc_nonnull_all
+ static Directory *Allocate(const char *path);
+
+public:
+ /**
+ * Default constructor, needed for #detached_root.
+ */
+ Directory() = default;
+ ~Directory();
+
/**
* Generic constructor for #Directory object.
*/
diff --git a/test/DumpPlaylist.cxx b/test/DumpPlaylist.cxx
index 231ae31a..612f5482 100644
--- a/test/DumpPlaylist.cxx
+++ b/test/DumpPlaylist.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "TagSave.hxx"
#include "song.h"
+#include "Directory.hxx"
extern "C" {
#include "io_thread.h"
@@ -37,6 +38,8 @@ extern "C" {
#include <unistd.h>
#include <stdlib.h>
+Directory::~Directory() {}
+
static void
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
const gchar *message, G_GNUC_UNUSED gpointer user_data)
diff --git a/test/TestQueuePriority.cxx b/test/TestQueuePriority.cxx
index 860015ff..01f39a00 100644
--- a/test/TestQueuePriority.cxx
+++ b/test/TestQueuePriority.cxx
@@ -7,6 +7,8 @@ extern "C" {
Directory detached_root;
+Directory::~Directory() {}
+
struct song *
song_dup_detached(const struct song *src)
{